一、cv2.findContours()
二、.append
三、处理轮廓
四、错误处理
1.视频未读入
warning如下:
报错如下:
Traceback (most recent call last):
File "D:/W/projects/project1/detection_by_SOD_video_0413_multi-target.py", line 293, in <module>
run()
File "D:/W/projects/project1/detection_by_SOD_video_0413_multi-target.py", line 288, in run
queue_img_get()
File "D:/W/projects/project1/detection_by_SOD_video_0413_multi-target.py", line 276, in queue_img_get
frame = cv2.resize(frame, (416, 416)) # resize到416*416
cv2.error: OpenCV(3.4.2) C:\projects\opencv-python\opencv\modules\imgproc\src\resize.cpp:4044: error: (-215:Assertion failed) !ssize.empty() in function 'cv::resize'
主函数如下图:
...
def run():
queue_img_get()
if __name__ == '__main__':
run()
在主函数中加入打印一句:
def run():
queue_img_get()
if __name__ == '__main__':
run()
print('end')
运行后发现结尾并没有打印出’end’一词,证明程序根本没有运行完。
参考了这位博主和这位博主的帖子,推测我可能也是视频中的帧数目不匹配导致的。
根据博主的指示,我在queue_img_get()函数的while循环中加入了如下内容:
if is_opened == False:
break
成功运行,并且warning也无了:
7
[32.0, 65.8923405612245, 23.919999999999998, 118.59375, 221.51275510204087, 535.580388767077]
[(243, 55, 85, 59), (0, 67, 56, 61)]
[535.580388767077, 221.51275510204087]
end
Process finished with exit code 0