IndexError at cv2.minAreaRect(contours[0])
I keep getting an IndexError at cv2.minAreaRect and my screen only displays a white screen. I'm new to python (java developer) I have absolutely no idea what's going on. Some help would be greatly appreciated!
Code is running on a Raspberry Pi3 connecting to an IP Camera. Can successfully connect to camera via browser. Also I'm trying to detect the green color range so no idea how HSV ranges work.
PS: Sorry about the ugly formatting, pasting from eclipse to here breaks everything. I can't post a pastebin link either.
#imports
import cv2
import numpy as np
import time
import argparse
import array
from collections import deque
from networktables import NetworkTables
#NetworkTables information
NetworkTables.initialize(server='OPENCV.ORG WONT LET ME DO IP')
Table = NetworkTables.getTable("table")
array.array('i')
cap = cv2.VideoCapture('OPENCV.ORG WONT LET ME DO IP')
while(True):
try:
# Capture frame-by-frame
ret, frame = cap.read()
#set color to HSV
gray = cv2.cvtColor(frame,cv2.COLOR_BGR2HSV);
#set color range
greenLower = (120, 100, 100) #adjust as needed
greenUpper = (109, 48, 89)
#set color range
bin = cv2.inRange(gray, greenLower, greenUpper)
#Our operations on the frame come here
bin = cv2.dilate(bin, None) # fill some holes
bin = cv2.dilate(bin, None)
bin = cv2.erode(bin, None) # dilate made our shape larger, revert that
bin = cv2.erode(bin, None)
bin, contours, hierarchy = cv2.findContours(bin, cv2.RETR_LIST, cv2.CHAIN_APPROX_SIMPLE)
#find box coordinates, if break add while
rc = cv2.minAreaRect(contours[0])
box = cv2.boxPoints(rc)
for p in box:
pt = (p[0],p[1])
cv2.circle(ret,pt,5,(200,0,0),2)
#Display the resulting frame
cv2.imshow('frame',bin) #shows the frame to screen
if cv2.waitKey(1) & 0xFF == ord('q'): #if 'q' key is pressed, end feed
break
except IndexError:
print("No Contours Found")
#safely end code sequence
cap.release()
cv2.destroyAllWindows()