OpenCV 未检测到对角线检测

时间:2021-07-20 14:13:36

标签: python opencv

我一直在尝试使用 openCV PHoughLine 检测来检测屏幕上的线条,但是由于某种原因,虽然我的程序能够检测水平线和垂直线,但它无法检测对角线。有人可以帮我确定为什么会这样。谢谢!

 while time.time() < timeout:
   try:
      (x,y)=pyautogui.locateCenterOnScreen(loc1, region=(round(width*0.35),round(depth*0.15),round(width * 0.35),round(depth* 0.75)),grayscale=False,confidence =  0.70)
      #pyautogui.moveTo(x,y+26)
      time.sleep(0.5)
      #pyautogui.click(x,y+26)
      time.sleep(0.5)
      if (__findline__== False):
         pyautogui.rightClick(x,y+26)
      else:
         img1 = pyautogui.screenshot(region=(x-150,y-150,300,300))
         img1.save(loc2)
         img = cv2.imread(loc2)
         gray = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
         edges = cv2.Canny(gray,50,150,apertureSize = 3)
         lines = cv2.HoughLinesP(edges,1,np.pi/180,100,25,10) #the fifth param is minLineLength, and the sixth param is maxLineGap
         
         for i in range(len(lines)):
            for x1,y1,x2,y2 in lines[i]:
               cv2.line(img,(x1,y1),(x2,y2),(0,255,0),2)
                  
         cv2.imwrite(loc2, img)

注意检测到的线是绿色的。

enter image description here

0 个答案:

没有答案
相关问题