I'm trying to "fix" data output from a function (OpenCV v3, HoughLinesP). The first "row" of the output is always "None"... while the rest of the output seems to work just fine.
I'm trying to check for that first row (actually, any row) that is "None" and assign it a value of "0" so that I can iterate over the array.
Right now I have this (but it doesn't seem to work):
import cv2
import numpy as np
import imutils
np.set_printoptions(threshold=np.inf) #to print entire array, no truncation
LOWER_BOUND = 55 #cv2.threshold()
UPPER_BOUND = 255 #cv2.threshold()
CANNY_LOWER_BOUND = 10 #cv2.Canny()
CANNY_UPPER_BOUND = 250 #cv2.Canny()
MIN_LINE_LENGTH = 2 #HoughLinesP()
MAX_LINE_GAP = 100 #HoughLinesP()
HOUGH_THETA = np.pi/180 #HoughLinesP() angle resolution of the accumulator, radians
HOUGH_THRESHOLD = 25 #HoughLinesP()
HOUGH_RHO = 1 #HoughLinesP() rho, Distance resolution of the accumulator, pixels
bkgnd = cv2.bgsegm.createBackgroundSubtractorMOG()
camera = cv2.VideoCapture('/home/odroid/Desktop/python_scripts/test/test_images/Edited_Foam_Dispense_Short.mp4')
run_once = 0
while(run_once <= 1):
(grabbed, frame) = camera.read()
img_sub = bkgnd.apply(frame)#, learningRate = 0.001)
canny_threshold = cv2.Canny(img_sub, CANNY_LOWER_BOUND, CANNY_UPPER_BOUND)
hlines = cv2.HoughLinesP(canny_threshold, HOUGH_RHO, HOUGH_THETA, MIN_LINE_LENGTH, MAX_LINE_GAP)
#************************* The if statement for the empty element*****
if hlines is None:
hlines[0] = [0, 0, 0, 0]
else:
for l in hlines:
leftx, boty, rightx, topy = l[0]
line = Line((leftx, boty), (rightx, topy))
line.draw(frame, (0, 255, 0), 2)
#*************************************************************
cv2.imshow('canny_threshold', canny_threshold)
cv2.imshow("frame", frame)
run_once = 1 + run_once
if cv2.waitKey(1) & 0xFF == ord('q'):
break
camera.release()
cv2.destroyAllWindows()
And here's the error I'm getting:
Traceback (most recent call last):
File "test3.py", line 41, in hlines[0] = [0, 0, 0, 0] TypeError: 'NoneType' object does not support item assignment
What I'm trying to do is assign that first row of hlines to [[0,0,0,0]] so it matches the rest of the array (meaning that there's data). Why is this not working?