Skip to content

Commit

Permalink
Create synchronized.py
Browse files Browse the repository at this point in the history
  • Loading branch information
elerac committed Jul 2, 2020
1 parent a97dd32 commit cacd359
Showing 1 changed file with 43 additions and 0 deletions.
43 changes: 43 additions & 0 deletions examples/synchronized.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
import EasyPySpin
import cv2

SCALE = 0.5

def main():
cap_primary = EasyPySpin.VideoCapture(0)
cap_secondary = EasyPySpin.VideoCapture(1)

cap_primary.set(cv2.CAP_PROP_TRIGGER, True) #TriggerMode -> On
#import PySpin
#cap_primary.cam.TriggerSource.SetValue(PySpin.TriggerSource_Software)

cap_sync = EasyPySpin.SynchronizedVideoCapture(cap_primary, cap_secondary)

while True:
ret, frame = cap_sync.read()
frame_primary = frame[0]
frame_secondary = frame[1]

img_show_primary = cv2.resize(frame_primary, None, fx=SCALE, fy=SCALE)
img_show_secondary = cv2.resize(frame_secondary, None, fx=SCALE, fy=SCALE)
cv2.imshow("primary", img_show_primary)
cv2.imshow("secondary", img_show_secondary)
key = cv2.waitKey(1)
if key==ord("q"):
break
elif key==ord("c"):
import datetime
time_stamp = datetime.datetime.now().strftime("%Y%m%d%H%M%S")
filename0 = "synchronized-{0}-{1}.png".format(time_stamp, 0)
filename1 = "synchronized-{0}-{1}.png".format(time_stamp, 1)
cv2.imwrite(filename0, frame_primary)
cv2.imwrite(filename1, frame_secondary)
print("Image saved at {}".format(filename0))
print("Image saved at {}".format(filename1))
print()

cv2.destroyAllWindows()
cap_sync.release()

if __name__=="__main__":
main()

0 comments on commit cacd359

Please sign in to comment.