colabcam


Namecolabcam JSON
Version 1.0.3 PyPI version JSON
download
home_pagehttps://pypi.org/project/colabcam
SummaryProcess image from webcam in colab
upload_time2023-03-27 05:43:56
maintainer
docs_urlNone
authorKuoYuan Li
requires_python
license
keywords colab webcam javascript take_photo take_img record_video_timed
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Author:KuoYuan Li
[![N|Solid](https://images2.imgbox.com/8f/03/gv0QnOdH_o.png)](https://sites.google.com/ms2.ccsh.tn.edu.tw/pclearn0915)  
wrap the javascript code to handle image from webcam in colab  
本package提供一系列在 colab 中操作webcam的方法  
在colab中使用之前請先進行安裝  
```
!pip install colabcam
```
	
##### webcam 拍照存檔
##### (take a photo from webcam and save to 1.jpg)
```python
import colabcam
colabcam.take_photo("1.jpg")
```
### 動態顯示人臉框及文字(cv2只支援英數字)
### (demo with mediapipe face_detection)
```python
#Note:bbox(人臉框)是另外疊加顯示的,速度會有延遲是正常的
import mediapipe as mp
import colabcam
import numpy as np
import cv2
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
            

Raw data

            {
    "_id": null,
    "home_page": "https://pypi.org/project/colabcam",
    "name": "colabcam",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "colab,webcam,javascript,take_photo,take_img,record_video_timed",
    "author": "KuoYuan Li",
    "author_email": "funny4875@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/4c/40/825fa07131d01c42078c314f0b87006ab1e231e8aa946e6ec3f86cef1cd0/colabcam-1.0.3.tar.gz",
    "platform": null,
    "description": "# Author:KuoYuan Li\n[![N|Solid](https://images2.imgbox.com/8f/03/gv0QnOdH_o.png)](https://sites.google.com/ms2.ccsh.tn.edu.tw/pclearn0915)  \nwrap the javascript code to handle image from webcam in colab  \n\u672cpackage\u63d0\u4f9b\u4e00\u7cfb\u5217\u5728 colab \u4e2d\u64cd\u4f5cwebcam\u7684\u65b9\u6cd5  \n\u5728colab\u4e2d\u4f7f\u7528\u4e4b\u524d\u8acb\u5148\u9032\u884c\u5b89\u88dd  \n```\n!pip install colabcam\n```\n\t\n##### webcam \u62cd\u7167\u5b58\u6a94\n##### (take a photo from webcam and save to 1.jpg)\n```python\nimport colabcam\ncolabcam.take_photo(\"1.jpg\")\n```\n### \u52d5\u614b\u986f\u793a\u4eba\u81c9\u6846\u53ca\u6587\u5b57(cv2\u53ea\u652f\u63f4\u82f1\u6578\u5b57)\n### (demo with mediapipe face_detection)\n```python\n#Note:bbox(\u4eba\u81c9\u6846)\u662f\u53e6\u5916\u758a\u52a0\u986f\u793a\u7684\uff0c\u901f\u5ea6\u6703\u6709\u5ef6\u9072\u662f\u6b63\u5e38\u7684\nimport mediapipe as mp\nimport colabcam\nimport numpy as np\nimport cv2\nmp_face_detection = mp.solutions.face_detection\nface_detection = mp_face_detection.FaceDetection()\n# start streaming video from webcam\ncolabcam.video_stream()\n# label for video\nlabel_html = '\u986f\u793a\u4e2d...(\u9ede\u64ca\u756b\u9762\u4ee5\u7d50\u675f\u986f\u793a)'\n# initialze bounding box to empty\nbbox = ''\nwhile True:  \n  js_reply = colabcam.video_frame(label_html, bbox)  \n  if not js_reply:break  \n  # convert JS response to OpenCV Image  \n  img = colabcam.js_to_image(js_reply[\"img\"])  \n  results = face_detection.process(img)  \n  frame_height,frame_width=np.shape(img)[0:2]  \n  overlapImg = np.zeros([frame_height,frame_width,4], dtype=np.uint8)  \n  if results.detections:  \n    for detection in results.detections:  \n      box = detection.location_data.relative_bounding_box  \n      x, y, w, h =int(box.xmin*frame_width),int(box.ymin*frame_height), \\\n              int(box.width*frame_width),int(box.height*frame_height)         \n      if w>0 and h>0:  \n        overlapImg = cv2.rectangle(overlapImg,(x,y),(x+w,y+h),(255,0,0),2)  \n        cv2.putText(overlapImg,'text test',(x,y-20),cv2.FONT_HERSHEY_SIMPLEX,1,(255,0,0),2)  \n    bbox = colabcam.cvImg2bbox(overlapImg)  \n```\n\n\n\n\nLicense\n----\n\nMIT",
    "bugtrack_url": null,
    "license": "",
    "summary": "Process image from webcam in colab",
    "version": "1.0.3",
    "split_keywords": [
        "colab",
        "webcam",
        "javascript",
        "take_photo",
        "take_img",
        "record_video_timed"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "4c40825fa07131d01c42078c314f0b87006ab1e231e8aa946e6ec3f86cef1cd0",
                "md5": "9615ecab230b2a14ec176abb9b1dd1d3",
                "sha256": "18ab3e407bf23bd0c044a45dd5010191b2551b40d57ede1ccbff65365026e1d6"
            },
            "downloads": -1,
            "filename": "colabcam-1.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "9615ecab230b2a14ec176abb9b1dd1d3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 5387,
            "upload_time": "2023-03-27T05:43:56",
            "upload_time_iso_8601": "2023-03-27T05:43:56.902803Z",
            "url": "https://files.pythonhosted.org/packages/4c/40/825fa07131d01c42078c314f0b87006ab1e231e8aa946e6ec3f86cef1cd0/colabcam-1.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-03-27 05:43:56",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "colabcam"
}
        
Elapsed time: 0.64111s