Через камеру решил выделить контура.
До этого пробовал через видео. Там работает.
Вылетает
list index out of range.
Может нужно как то видео-поток обработать через numpy?
from ueye.ueye_camera import UeyeCameraCapture
import cv2
import numpy as np
cam1 = UeyeCameraCapture(0)
def camera1():
ret, frame = cam1.read()
thresh = cv2.threshold(frame, 100, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)[1]
contours, hierarchy = cv2.findContours(thresh, cv2.RETR_TREE, cv2.CHAIN_APPROX_SIMPLE)
sortcontourArea = [cnt for cnt in contours if 0 < cv2.contourArea(cnt) < 2000]
good_contours = sorted(sortcontourArea, key=cv2.contourArea)
contour1 = good_contours[0]
contour2 = good_contours[1]
cv2.drawContours(frame, contour1, 0, 255, -1)
cv2.drawContours(frame, contour2, 0, 255, -1)
cv2.imshow('frame', frame)
while True:
camera1()
if cv2.waitKey(1) & 0xFF == ord('q'):
break
cv2.destroyAllWindows()
Camera Connection success
Traceback (most recent call last):
File "D:/Crea/P/Python/lesson1/npy/np6.py", line 25, in <module>
camera1()
File "D:/Crea/P/Python/lesson1/npy/np6.py", line 15, in camera1
contour1 = good_contours[0]
IndexError: list index out of range
destructor called
Camera connection closed