I am in the process of making a Real-Time feedback program using Python and OpenCV: a webcam will be observing a process and generating feedbacks based on what is happening.
Here is my code:
points = get_points_xml()
rect = cv2.boundingRect(np.array(points))
x, y, w, h = rect
cap = cv2.VideoCapture(0)
while (True):
ret, frame = cap.read()
cropped = frame[y: y + h, x: x + w]
ycb = cv2.cvtColor(cropped.copy(), cv2.COLOR_BGR2YCrCb)
y, cr, br = cv2.split(ycb)
blur = cv2.blur(y, (5, 5))
size = blur.size
ret, thresh = cv2.threshold(blur, 60, 255, cv2.THRESH_BINARY)
saturated, area_sat = get_saturated(thresh)
print(saturated, "pixels", area_sat, "cm2")
ret, thresh = cv2.threshold(blur, 80, 140, cv2.THRESH_BINARY_INV)
empty, area_empty = get_saturated(thresh)
print(empty, "pixels", area_empty, "cm2")
unsaturated = size - saturated - empty
area_unsat = unsaturated/cm2
print(unsaturated, "pixels", area_unsat, "cm2")
if (cv2.waitKey(1) & 0xFF == ord('q')):
break
cap.release()
cv2.destroyAllWindows()
Executing the line
cropped = frame[y: y + h, x: x + w]
results in the following error:
TypeError: only integer scalar arrays can be converted to a scalar index
This is weird, because in the 'first round' of the while loop my program is working fine, then in the 'second round' of the while loop it prompts me the above mentioned error.
What could be causing this?