Feb-08-2025, 03:48 AM
I was trying to use a tracebar to change the value of shresholds for Canny. Here is my code:
Please help
#HoughLinesP import cv2 import numpy as np filename = input("Enter name of file to process: ") original = cv2.imread(filename) height, width = original.shape[:2] Max=1000 Min=1000 def blank(x): # null function for trackbar pass; MaxVal = (f'MaxVal 0: {Max-1}') MinVal = (f'MinVall 0: {Min-1}') cv2.namedWindow('window', cv2.WINDOW_NORMAL) cv2.resizeWindow('window', width, height) cv2.createTrackbar(MaxVal, 'window', 0, Max-1, blank) cv2.createTrackbar(MinVal, 'window', 0, Min-1, blank) while True: maxv = cv2.getTrackbarPos(MaxVal, 'window') minv = cv2.getTrackbarPos(MinVal, 'window') edge=cv2.Canny(original,minv,maxv) lines=cv2.HoughLinesP( edge, 1, np.pi/180, threshold =100, # lines minLineLength=20, maxLineGap =10) for i in range(len(lines)): for x1, y1, x2, y2 in lines[i]: cv2.line(original, (x1, y1), (x2, y2), (0, 255, 0), 2) cv2.imshow("houghline",original) # cv2.waitKey() # cv2.destroyAllWindows() if cv2.waitKey(1) == 32: # stop when space bar hit cv2.destroyAllWindows()When I run, I got this error:
Quote:Enter name of file to process: sidewalk.jpg
QSocketNotifier: Can only be used with threads started with QThread
QStandardPaths: wrong permissions on runtime directory /run/user/1000, 0770 instead of 0700
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
libpng warning: iCCP: known incorrect sRGB profile
Traceback (most recent call last):
File "/home/ricky/Desktop/moduleç»ä¹ /module5.py", line 227, in <module>
for i in range(len(lines)):
^^^^^^^^^^
TypeError: object of type 'NoneType' has no len()
Please help