Use contours in a video?
This is the program I use for drawing all the contours around an image
import numpy as np
import cv2
im = cv2.imread('test.jpg')
imgray = cv2.cvtColor(im,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(imgray,127,255,0)
im2, contours, hierarchy = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
For drawing contours in a video, I use this program.
import cv2
cap = cv2.VideoCapture(0)
while True:
ret,frame=cap.read()
gray = cv2.cvtColor(frame,cv2.COLOR_BGR2GRAY)
ret,thresh = cv2.threshold(gray,140,255,0)
image,contours,hie = cv2.findContours(thresh,cv2.RETR_TREE,cv2.CHAIN_APPROX_SIMPLE)
frame = cv2.drawContours(frame, contours, 3, (0,255,0), 3)
cv2.imshow("vid",frame)
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cap.release() cv2.destroyAllWindows()
Now the problem is that when I run the second program, there are multiple errors
1-> Need more than 2 values to unpack.
2-> When I remove the image parameter from the findContours(), and try to display, it still gives me an error.
Can someone please explain to me why this is happening?
Thanks in advance! :)