TShopping

標題: Python + OpenCV 擷取部分桌面圖片 [打印本頁]

作者: woff    時間: 2020-10-1 17:10
標題: Python + OpenCV 擷取部分桌面圖片
首先打開youtube影片




視窗化並縮小到右側
我的桌面解析度是1600 * 900
在jupyter notebook輸入代碼

  1. from PIL import ImageGrab
  2. import numpy as np
  3. import cv2

  4. img = ImageGrab.grab(bbox=(1200,100,1600,700)) #bbox specifies specific region (bbox= x,y,width,height *starts top-left)
  5. img_np = np.array(img) #this is the array obtained from conversion
  6. frame = cv2.cvtColor(img_np, cv2.COLOR_BGR2GRAY) #擷取寬度 1200-1600 高度 100-700的灰階圖片
  7. cv2.imshow("test", frame) #秀出擷取圖片並顯示框架標題
  8. cv2.waitKey(0)
  9. cv2.destroyAllWindows()
複製代碼



結果圖


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






歡迎光臨 TShopping (http://www.tshopping.com.tw/) Powered by Discuz! X3.2