简体   繁体   中英

Error capturing video with opencv (python)

I am currently doing a motion detection project that records video when motion is detected. I am having an error when recording the video.

This is the following error:

error: (-215) img.cols == width && img.rows == height && channels == 3 in function cv::mjpeg::MotionJpegWriter::write

This is my code:

def takevid():

Your problem is scope of the variable frame . You either need to declare frame outside the while loop, just globally in the file, or pass it as an argument to takevid . Currently frame is only available in the while loop, but that when you call takevid only the global scope (ie camera ) is accessible, not that of the while loop.

The error is telling you that the size of frame is wrong, and most likely you would find the shape is (0,0) because there is nothing in that variable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM