TShopping

 找回密碼
 註冊
搜索
查看: 1761|回復: 0
打印 上一主題 下一主題

[教學] Python + OpenCV 抓取桌面圖像並滑鼠點擊辨識圖片

[複製鏈接]
跳轉到指定樓層
1#
發表於 2020-10-22 17:39:53 | 只看該作者 回帖獎勵 |倒序瀏覽 |閱讀模式
 
Push to Facebook
  1. from PIL import ImageGrab
  2. import numpy as np
  3. import cv2
  4. import pyautogui
  5. cat_haar = cv2.CascadeClassifier(r"D:\opencv\build\x64\vc14\bin\data\cascade.xml")
  6. img = ImageGrab.grab(bbox=(1200,100,1600,700)) #bbox specifies specific region (bbox= x,y,width,height *starts top-left)
  7. img_np = np.array(img) #this is the array obtained from conversion

  8. gray = cv2.cvtColor(img_np, cv2.COLOR_BGR2GRAY)
  9. cat = cat_haar.detectMultiScale(gray, 1.06, 1,minSize=(50, 50))
  10. # 繪製貓的方框
  11. for (x, y, w, h) in cat:
  12.     cv2.rectangle(img_np, (x, y), (x + w, y + h), (0, 255, 0), 2)
  13.    
  14. #     pyautogui.click(10,5)           
  15. #     pyautogui.click(1200+x+w/2,  100+y + h/2,button='left') # 在(1200+x+w/2,  100+y + h/2)單擊滑鼠,預設左鍵
  16.     pyautogui.click(1200+x+w/2,  100+y + h/2,button='right')
  17. # 顯示成果
  18. # cv2.namedWindow('img', cv2.WINDOW_NORMAL)  #正常視窗大小
  19. # cv2.imshow('img', img_np)                     #秀出圖片

  20. # frame = cv2.cvtColor(img_np, cv2.COLOR_BGR2GRAY) #擷取寬度 1200-1600 高度 100-700的灰階圖片
  21. # cv2.imshow("test", frame) #秀出擷取圖片並顯示框架標題
  22. cv2.waitKey(0)
  23. cv2.destroyAllWindows()
複製代碼

文章出處


網頁設計,網站架設 ,網路行銷,網頁優化,SEO - NetYea 網頁設計



 

臉書網友討論
*滑块验证:
您需要登錄後才可以回帖 登錄 | 註冊 |

本版積分規則



Archiver|手機版|小黑屋|免責聲明|TShopping

GMT+8, 2024-4-26 12:09 , Processed in 0.043546 second(s), 22 queries .

本論壇言論純屬發表者個人意見,與 TShopping綜合論壇 立場無關 如有意見侵犯了您的權益 請寫信聯絡我們。

Powered by Discuz! X3.2

© 2001-2013 Comsenz Inc.

快速回復 返回頂部 返回列表