前提・実現したいこと
for文で複数枚の画像をハフ変換するプログラムで、下記のエラーが出て困っています。
このエラーはどういった内容なのでしょうか。また解決方法を教えていただきたいです。よろしくお願いいたします。
発生している問題・エラーメッセージ
--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) AttributeError: 'NoneType' object has no attribute 'rint' The above exception was the direct cause of the following exception: TypeError Traceback (most recent call last) <ipython-input-18-169dfba55118> in <module> 117 img_ga = cv2.GaussianBlur(inv,(5,5),0) 118 circles = cv2.HoughCircles(img_ga.astype(np.uint8),cv2.HOUGH_GRADIENT,1,50,param1=10,param2=20,minRadius=5,maxRadius=80) --> 119 circles = np.uint16(np.around(circles)) 120 for i in circles[0,:]: 121 cv2.circle(inv,(i[0],i[1]),i[2],(0,255,0),2) <__array_function__ internals> in around(*args, **kwargs) ~\anaconda3\lib\site-packages\numpy\core\fromnumeric.py in around(a, decimals, out) 3222 3223 """ -> 3224 return _wrapfunc(a, 'round', decimals=decimals, out=out) 3225 3226 ~\anaconda3\lib\site-packages\numpy\core\fromnumeric.py in _wrapfunc(obj, method, *args, **kwds) 56 bound = getattr(obj, method, None) 57 if bound is None: ---> 58 return _wrapit(obj, method, *args, **kwds) 59 60 try: ~\anaconda3\lib\site-packages\numpy\core\fromnumeric.py in _wrapit(obj, method, *args, **kwds) 45 except AttributeError: 46 wrap = None ---> 47 result = getattr(asarray(obj), method)(*args, **kwds) 48 if wrap: 49 if not isinstance(result, mu.ndarray): TypeError: loop of ufunc does not support argument 0 of type NoneType which has no callable rint method
該当のソースコード
python
1for i in range (1550,1560): 2 3 img = cv2.imread('DSC0'+str(i)+'.jpg',0) 4 height = img.shape[0] 5 width = img.shape[1] 6 resize_img = cv2.resize(img,(int(width*0.5),int(height*0.5))) 7 8 #ganma 9 img_blur = cv2.GaussianBlur(resize_img,(499,499),0) 10 height = img_blur.shape[0] 11 width = img_blur.shape[1] 12 np.clip(height, 1,254) 13 np.clip(width,1,254) 14 b = img_blur/255.0 15 g = np.log(0.5)/np.log(b) 16 img2 = 255.0*np.power(resize_img/255.0,g) 17 cv2.imwrite('ganma-'+str(i)+'.jpg',img2) 18 19 #contrast 20 img3 = cv2.imread('ganma-'+str(i)+'.jpg',0) 21 clahe = cv2.createCLAHE(clipLimit=2.0, tileGridSize=(8,8)) 22 cl2 = clahe.apply(img3.astype(np.uint8)) 23 cv2.imwrite('cl-'+str(i)+'.jpg',cl2) 24 25 #threshold 26 threshold = 100 27 ret, img_thresh = cv2.threshold(cl1, threshold, 255, cv2.THRESH_BINARY) 28 cv2.imwrite('th-'+str(i)+'.jpg', img_thresh) 29 30 #morphology 31 kernel = np.ones((5,5),np.uint8) 32 closing = cv2.morphologyEx(img_thresh,cv2.MORPH_CLOSE,kernel) 33 cv2.imwrite('mor-'+str(i)+'.jpg',closing) 34 frontimg = closing 35 36 #Background subtraction 37 fgbg = cv2.bgsegm.createBackgroundSubtractorMOG() 38 fgmask = fgbg.apply(backimg) 39 fgmask = fgbg.apply(frontimg) 40 cv2.imwrite('front-'+str(i)+'.jpg',fgmask) 41 42 #remove 43 def remove_objects(img, lower_size=None, upper_size=None): 44 nlabels, labels, stats, centroids = cv2.connectedComponentsWithStats(img) 45 sizes = stats[1:, -1] 46 _img = np.zeros((labels.shape)) 47 for i in range(1, nlabels): 48 if (lower_size is not None) and (upper_size is not None): 49 if lower_size < sizes[i - 1] and sizes[i - 1] < upper_size: 50 _img[labels == i] = 255 51 elif (lower_size is not None) and (upper_size is None): 52 if lower_size < sizes[i - 1]: 53 _img[labels == i] = 255 54 elif (lower_size is None) and (upper_size is not None): 55 if sizes[i - 1] < upper_size: 56 _img[labels == i] = 255 57 return _img 58 #org_img= cv2.imread('front-'+str(i)+'.jpg',0) 59 img_remove = remove_objects(fgmask,lower_size=50, upper_size=None) 60 cv2.imwrite('remove-'+str(i)+'.jpg',img_remove) 61 62 #inversion 63 inv = cv2.bitwise_not(img_remove) 64 65 #haugh 66 wb = excel.Workbook() 67 ws = wb.active 68 ws['A1'] = "width" 69 ws['B1'] = "height" 70 ws['C1'] = "r-pixel" 71 ws['D1'] = "d-pixel" 72 ws['E1'] = "r-μm" 73 ws['F1'] = "d-μm" 74 ws['G1'] = "area-μm" 75 ws.title = "Sheet_1" 76 img_ga = cv2.GaussianBlur(inv,(5,5),0) 77 circles = cv2.HoughCircles(img_ga.astype(np.uint8),cv2.HOUGH_GRADIENT,1,50,param1=10,param2=20,minRadius=5,maxRadius=80) 78 circles = np.uint16(np.around(circles)) 79 for i in circles[0,:]: 80 cv2.circle(inv,(i[0],i[1]),i[2],(0,255,0),2) 81 cv2.circle(inv,(i[0],i[1]),2,(0,0,255),3) 82 83 ws.append((float(i[0]), float(i[1]),float(i[2]),float(i[2]*2),float(i[2]*41.1*pow(10,-3)),float(i[2]*2*41.1*pow(10,-3)),float((i[2]*41.1)*(i[2]*41.1)*math.pi))) 84 85 wb.save(r"hahu"+str(i)+".xlsx") 86 87 cv2.imwrite('hahu'+str(i)+'.jpg',inv)
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2021/01/12 09:22