请问 从下面第一段代码里引用第二段代码,为什么会引用不成功呢?
-
第一段: import sensor, image, time from juge_shapes import juge sensor.reset() sensor.set_pixformat(sensor.RGB565) sensor.set_framesize(sensor.QQVGA) # we run out of memory if the resolution is much bigger... 图像像素大小QQVGA是160✖120 sensor.skip_frames(30) sensor.set_auto_gain(False) # must turn this off to prevent image washout... sensor.set_auto_whitebal(False) # must turn this off to prevent image washout... sensor.set_auto_exposure(True) clock = time.clock() #black = (25, 95, 77, 22, -16, 63) # red #black = (29, 2, -35, 30, 46, -27) black = (34, 0, -41, 25, 60, -37) def find_max(blobs): #寻找最大色块函数定义 max_pixels=0 #通过像素比较 for blob in blobs: #blob[0,1,2,3,4]=x,y,w,h,pixels (int) if blob[4]>max_pixels: max_blob=blob max_pixels=blob[4] return max_blob i_r = 0 i_s = 0 i_c = 0 lists = [] while(True): img = sensor.snapshot() shape = juge(img) print(shape) 第二段: import sensor, image, time #black = (25, 95, 77, 22, -16, 63) # red #black = (29, 2, -35, 30, 46, -27) black = (34, 0, -41, 25, 60, -37) i_r = 0 i_s = 0 i_c = 0 lists = [] def find_max(blobs): #寻找最大色块函数定义 max_pixels=0 #通过像素比较 for blob in blobs: #blob[0,1,2,3,4]=x,y,w,h,pixels (int) if blob[4]>max_pixels: max_blob=blob max_pixels=blob[4] return max_blob def juge(img): circles = img.find_circles(threshold = 4500, x_margin = 10, y_margin = 10, r_margin = 10,r_min = 5, r_max = 100, r_step = 2) if circles: for c in circles: img.draw_circle(c.x(), c.y(), c.r(), color = (255, 0, 0)) lists.append("circles") #print("find circles") else: rects = img.find_rects(threshold = 20000) if rects: for r in rects: img.draw_rectangle(r.rect(), color = (255, 0, 0)) for p in r.corners(): img.draw_circle(p[0], p[1], 5, color = (0, 255, 0)) lists.append("rects") #print("find rects") else: blobs = img.find_blobs([black],area_threshold=50, pixels_threshold=50) if blobs: max_blob=find_max(blobs) img.draw_rectangle(max_blob.rect()) img.draw_cross(max_blob.cx(),max_blob.cy()) k = max_blob.pixels() / max_blob.area() if(k <= 0.6): lists.append("sanjiao") # print("find sanjiao") #continue num_r = lists.count("rects") num_c = lists.count("circles") num_s = lists.count("sanjiao") if(num_r > num_s and num_r > num_c): i_r+=1 print(num_r, num_s ,num_c) if(i_r >=5): # print("find rects") i_r = 0 lists = [] return 1 if(num_s > num_c and num_s > num_r): i_s+=1 print(num_r,num_s,num_c) if(i_s >=5): #print("find sanjiao") i_s = 0 lists = [] return 2 if(num_c > num_s and num_c > num_r): i_c+=1 print(num_r,num_s,num_c) if(i_c >=5): #print("find circles") i_c = 0 lists = [] return 3
-
https://singtown.com/learn/50029/
你的代码瞎写的。逻辑不对。