I have written below code to read video from camera to display and save .
when I run the below code with option 0 in VideoCapture(0), it works fine and display my webcam video, when I change it to 1 in VideoCapture(1) to get the video from third party camera, I get the error.
I am using the 3rd party camera, with their software it plays the video , I need to capture using my python code ..
with the apbase code qt example also it plays the video
I am not able to play using the below python code
import cv2
import numpy as np
import time
def nothing(x):
pass
cv2.namedWindow('images')
switch = 'Recording'
cv2.createTrackbar(switch, 'images',0,1,nothing)
cap = cv2.VideoCapture(0)
def writeVideo(frmae):
pass
switchstatus = 0
currentpos = 0
fourccs = cv2.VideoWriter_fourcc(*'MJPG')
out = cv2.VideoWriter('sample.avi', fourccs, 20.0, (640,480))
created = 0
startrecord = 0
def RecordVideo(frame):
global out
global created;
global startrecord
print "In the Record video" ,created, startrecord
if created == 0 and startrecord ==1:
filename ='test.avi'
filename=time.strftime("%Y-%m-%d-%H-%M-%S")+'.avi'
print "filename", filename
out = cv2.VideoWriter(filename,fourccs, 20.0, (640,480))
created = 1;
out.write(frame)
elif created == 1 and startrecord ==1:
out.write(frame)
def positionChanged(s):
global currentpos
global created
global startrecord
print "position changed", s
currentpos = s
if s==1:
startrecord = 1
created = 0
else:
startrecord = 0
if created==1:
created =0
out.release()
def switchchanged(s):
global switchstatus;
if switchstatus != s:
switchstatus = s
positionChanged(s)
while(1):
ret, frame = cap.read()
RecordVideo(frame)
cv2.imshow('images',frame)
s = cv2.getTrackbarPos(switch,'images')
switchchanged(s)
if cv2.waitKey(1) & 0xFF == ord('q'):
out.release()
cv2.destroyAllWindows()
break
Error
File "C:\Python32Bit\video.py, lime 89, in cv2.imshow('images',frame)
eror :........\opencv\modules\hihggui\src\window.cpp:error:(-215) size.width>0 && size.height>0 in function cv::imshow
VideoCaptureby default useslibv4l2for video input devices. Installv4l-utilsand dov4l2-ctl --all. See if it displays your camera. - zindarodDShow. With your display webcam, runcap = cv2.VideoCapture(0+cv2.CAP_DSHOW), if it works then it is usingDSHOW. - zindarodcap = cv2.VideoCapture(0+cv2.CAP_FFMPEG). Btw, did you install OpenCV from source or opencv_python bindings? - zindarod