Skip to main content

Process image from webcam in colab

Project description

Author:KuoYuan Li

N|Solid
wrap the javascript code to handle image from webcam in colab
本package提供一系列在 colab 中操作webcam的方法

webcam 拍照存檔
(take a photo from webcam and save to 1.jpg)
import colabcam
colabcam.take_photo("1.jpg")

動態顯示人臉框及文字(cv2只支援英數字)

(demo with mediapipe face_detection)

import mediapipe as mp
import colabcam
mp_face_detection = mp.solutions.face_detection
face_detection = mp_face_detection.FaceDetection()
# start streaming video from webcam
colabcam.video_stream()
# label for video
label_html = '顯示中...(點擊畫面以結束顯示)'
# initialze bounding box to empty
bbox = ''
while True:  
  js_reply = colabcam.video_frame(label_html, bbox)  
  if not js_reply:break  
  # convert JS response to OpenCV Image  
  img = colabcam.js_to_image(js_reply["img"])  
  results = face_detection.process(img)  
  frame_height,frame_width=np.shape(img)[0:2]  
  overlapImg = np.zeros([frame_height,frame_width,4], dtype=np.uint8)  
  if results.detections:  
    for detection in results.detections:  
      box = detection.location_data.relative_bounding_box  
      x, y, w, h =int(box.xmin*frame_width),int(box.ymin*frame_height), \
              int(box.width*frame_width),int(box.height*frame_height)         
      if w>0 and h>0:  
        overlapImg = cv2.rectangle(overlapImg,(x,y),(x+w,y+h),(255,0,0),2)  
        cv2.putText(overlapImg,'text test',(x,y-20),cv2.FONT_HERSHEY_SIMPLEX,1,(255,0,0),2)  
    bbox = colabcam.cvImg2bbox(overlapImg)  

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

colabcam-1.0.2.tar.gz (5.2 kB view details)

Uploaded Source

File details

Details for the file colabcam-1.0.2.tar.gz.

File metadata

  • Download URL: colabcam-1.0.2.tar.gz
  • Upload date:
  • Size: 5.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.6.8

File hashes

Hashes for colabcam-1.0.2.tar.gz
Algorithm Hash digest
SHA256 309410d60bfdf7910d981b0d4cd1e8d4e3e4e3889397309b3bb6309278de4eaa
MD5 8997419422cae419fa70177b710682e6
BLAKE2b-256 d71d3354821f8927a72b2009d2d711f23a08fae161b3f8363f18adc386ba1370

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page