mirror of
https://github.com/Astatin3/vid-to-3d.git
synced 2026-06-08 16:18:01 -06:00
That was honestly a lot easier than I thought it would be
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
output/
|
||||||
|
|
||||||
# Byte-compiled / optimized / DLL files
|
# Byte-compiled / optimized / DLL files
|
||||||
__pycache__/
|
__pycache__/
|
||||||
*.py[cod]
|
*.py[cod]
|
||||||
|
|||||||
Generated
+8
@@ -0,0 +1,8 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
||||||
|
# Datasource local storage ignored files
|
||||||
|
/dataSources/
|
||||||
|
/dataSources.local.xml
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<profile version="1.0">
|
||||||
|
<option name="myName" value="Project Default" />
|
||||||
|
<inspection_tool class="PyPep8Inspection" enabled="false" level="WEAK WARNING" enabled_by_default="false" />
|
||||||
|
</profile>
|
||||||
|
</component>
|
||||||
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<component name="InspectionProjectProfileManager">
|
||||||
|
<settings>
|
||||||
|
<option name="USE_PROJECT_PROFILE" value="false" />
|
||||||
|
<version value="1.0" />
|
||||||
|
</settings>
|
||||||
|
</component>
|
||||||
Generated
+7
@@ -0,0 +1,7 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Black">
|
||||||
|
<option name="sdkName" value="Python 3.11 (Meshroom)" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.11 (Meshroom)" project-jdk-type="Python SDK" />
|
||||||
|
</project>
|
||||||
Generated
+8
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/video-2-3d.iml" filepath="$PROJECT_DIR$/.idea/video-2-3d.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+6
@@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
||||||
Generated
+8
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="PYTHON_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$" />
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
||||||
Binary file not shown.
@@ -0,0 +1,76 @@
|
|||||||
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
|
import cv2
|
||||||
|
import numpy as np
|
||||||
|
|
||||||
|
MINIMUM_SIMILARITY_THRESHOLD = 0.4
|
||||||
|
|
||||||
|
def process_video(video_path, min_similarity, output_folder):
|
||||||
|
cap = cv2.VideoCapture(video_path)
|
||||||
|
|
||||||
|
if not cap.isOpened():
|
||||||
|
print("Error opening video file")
|
||||||
|
return
|
||||||
|
|
||||||
|
match_frame = None
|
||||||
|
prev_frame = None
|
||||||
|
|
||||||
|
i = 0
|
||||||
|
|
||||||
|
while cap.isOpened():
|
||||||
|
ret, frame = cap.read()
|
||||||
|
if not ret: break
|
||||||
|
|
||||||
|
i += 1
|
||||||
|
|
||||||
|
print(f"Frame {i}: ", end='')
|
||||||
|
|
||||||
|
if prev_frame is None:
|
||||||
|
prev_frame = frame
|
||||||
|
match_frame = frame
|
||||||
|
print("Initial frame")
|
||||||
|
continue
|
||||||
|
|
||||||
|
cv2.imshow('Frame', frame)
|
||||||
|
|
||||||
|
similarity = orb_similarity(match_frame, frame)
|
||||||
|
|
||||||
|
print(f"Similarity: {similarity}, ", end='')
|
||||||
|
|
||||||
|
if similarity < min_similarity:
|
||||||
|
match_frame = prev_frame
|
||||||
|
|
||||||
|
if(not os.path.isdir(output_folder)):
|
||||||
|
os.mkdir(output_folder)
|
||||||
|
|
||||||
|
cv2.imwrite(os.path.join(output_folder, os.path.basename(video_path)+"-"+str(i)+".png"), match_frame)
|
||||||
|
print("Lost continuity, new match frame")
|
||||||
|
else:
|
||||||
|
print("Skipped!")
|
||||||
|
|
||||||
|
prev_frame = frame
|
||||||
|
|
||||||
|
if cv2.waitKey(1) == ord('q'): break
|
||||||
|
|
||||||
|
# Release the video capture object and close windows
|
||||||
|
cap.release()
|
||||||
|
cv2.destroyAllWindows()
|
||||||
|
|
||||||
|
|
||||||
|
orb = cv2.ORB_create()
|
||||||
|
|
||||||
|
def orb_similarity(img1, img2):
|
||||||
|
kp1, des1 = orb.detectAndCompute(img1, None)
|
||||||
|
kp2, des2 = orb.detectAndCompute(img2, None)
|
||||||
|
|
||||||
|
bf = cv2.BFMatcher(cv2.NORM_HAMMING, crossCheck=True)
|
||||||
|
matches = bf.match(des1, des2)
|
||||||
|
|
||||||
|
similarity = len(matches) / min(len(kp1), len(kp2))
|
||||||
|
return similarity
|
||||||
|
|
||||||
|
if len(sys.argv) != 4:
|
||||||
|
print("Usage: python main.py <video file> <min similarity threshold> <output folder>")
|
||||||
|
else:
|
||||||
|
process_video(sys.argv[1], float(sys.argv[2]), sys.argv[3])
|
||||||
Reference in New Issue
Block a user