| 
 | 
 
 
- from PIL import ImageGrab
 
 - import numpy as np
 
 - import cv2
 
 - import pyautogui
 
 - cat_haar = cv2.CascadeClassifier(r"D:\opencv\build\x64\vc14\bin\data\cascade.xml")
 
 - img = ImageGrab.grab(bbox=(1200,100,1600,700)) #bbox specifies specific region (bbox= x,y,width,height *starts top-left)
 
 - img_np = np.array(img) #this is the array obtained from conversion
 
  
- gray = cv2.cvtColor(img_np, cv2.COLOR_BGR2GRAY)
 
 - cat = cat_haar.detectMultiScale(gray, 1.06, 1,minSize=(50, 50))
 
 - # 繪製貓的方框
 
 - for (x, y, w, h) in cat:
 
 -     cv2.rectangle(img_np, (x, y), (x + w, y + h), (0, 255, 0), 2)
 
 -     
 
 - #     pyautogui.click(10,5)           
 
 - #     pyautogui.click(1200+x+w/2,  100+y + h/2,button='left') # 在(1200+x+w/2,  100+y + h/2)單擊滑鼠,預設左鍵
 
 -     pyautogui.click(1200+x+w/2,  100+y + h/2,button='right')
 
 - # 顯示成果
 
 - # cv2.namedWindow('img', cv2.WINDOW_NORMAL)  #正常視窗大小
 
 - # cv2.imshow('img', img_np)                     #秀出圖片
 
  
- # frame = cv2.cvtColor(img_np, cv2.COLOR_BGR2GRAY) #擷取寬度 1200-1600 高度 100-700的灰階圖片
 
 - # cv2.imshow("test", frame) #秀出擷取圖片並顯示框架標題
 
 - cv2.waitKey(0)
 
 - cv2.destroyAllWindows()
 
  複製代碼文章出處  
網頁設計,網站架設 ,網路行銷,網頁優化,SEO - NetYea 網頁設計  
 |   
 
 
 
 |