├── images ├── app_screen.jpeg ├── app_store.jpeg ├── play_store.jpeg ├── android_screen.jpeg └── pc_screen_of_droidcam_client.jpg ├── LICENSE ├── requirements.txt ├── using_USB ├── camera_input_from_IOS_devices.ipynb └── camera_input_from_Android.ipynb ├── using_wifi └── take_mobile_camera_input_using_IPWebcam.ipynb └── README.md /images/app_screen.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ravirajsinh45/connect_mobile_camera_with_computer_using_python/HEAD/images/app_screen.jpeg -------------------------------------------------------------------------------- /images/app_store.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ravirajsinh45/connect_mobile_camera_with_computer_using_python/HEAD/images/app_store.jpeg -------------------------------------------------------------------------------- /images/play_store.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ravirajsinh45/connect_mobile_camera_with_computer_using_python/HEAD/images/play_store.jpeg -------------------------------------------------------------------------------- /images/android_screen.jpeg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ravirajsinh45/connect_mobile_camera_with_computer_using_python/HEAD/images/android_screen.jpeg -------------------------------------------------------------------------------- /images/pc_screen_of_droidcam_client.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ravirajsinh45/connect_mobile_camera_with_computer_using_python/HEAD/images/pc_screen_of_droidcam_client.jpg -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2020 Ravirajsinh Dabhi 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | attrs==19.3.0 2 | backcall==0.1.0 3 | bleach==3.1.5 4 | certifi==2020.4.5.1 5 | chardet==3.0.4 6 | colorama==0.4.3 7 | decorator==4.4.2 8 | defusedxml==0.6.0 9 | entrypoints==0.3 10 | idna==2.9 11 | importlib-metadata==1.6.0 12 | ipykernel==5.3.0 13 | ipython==7.14.0 14 | ipython-genutils==0.2.0 15 | jedi==0.17.0 16 | Jinja2==2.11.2 17 | json5==0.9.5 18 | jsonschema==3.2.0 19 | jupyter-client==6.1.3 20 | jupyter-core==4.6.3 21 | jupyterlab==2.1.3 22 | jupyterlab-server==1.1.5 23 | MarkupSafe==1.1.1 24 | mistune==0.8.4 25 | nbconvert==5.6.1 26 | nbformat==5.0.6 27 | notebook==6.0.3 28 | numpy==1.18.4 29 | opencv-python==4.2.0.32 30 | packaging==20.4 31 | pandocfilters==1.4.2 32 | parso==0.7.0 33 | pickleshare==0.7.5 34 | prometheus-client==0.8.0 35 | prompt-toolkit==3.0.5 36 | Pygments==2.6.1 37 | pyparsing==2.4.7 38 | pyrsistent==0.16.0 39 | python-dateutil==2.8.1 40 | pywin32==227 41 | pywinpty==0.5.7 42 | pyzmq==19.0.1 43 | requests==2.23.0 44 | Send2Trash==1.5.0 45 | six==1.15.0 46 | terminado==0.8.3 47 | testpath==0.4.4 48 | tornado==6.0.4 49 | traitlets==4.3.3 50 | urllib3==1.25.9 51 | wcwidth==0.1.9 52 | webencodings==0.5.1 53 | wincertstore==0.2 54 | zipp==3.1.0 55 | -------------------------------------------------------------------------------- /using_USB/camera_input_from_IOS_devices.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Steps\n", 8 | "\n", 9 | "\n", 10 | "1. Download droidcam app on your IOS device from [app store](https://apps.apple.com/us/app/droidcam-wireless-webcam/id1510258102)\n", 11 | "\n", 12 | "2. Download and install [Dev47app](https://www.dev47apps.com/droidcam/windows/) setup on your pc for ios devices.\n", 13 | "\n", 14 | "3. open Droidcam on your iphone.\n", 15 | "\n", 16 | "4. open Droidcam app on pc \n", 17 | "\n", 18 | "5. Hit start button and you will get camera input on your computer screen\n", 19 | "\n", 20 | "6. Run below cell you will get input from your phone camera" 21 | ] 22 | }, 23 | { 24 | "cell_type": "code", 25 | "execution_count": null, 26 | "metadata": {}, 27 | "outputs": [], 28 | "source": [ 29 | "import cv2\n", 30 | "\n", 31 | "cap = cv2.VideoCapture(1)\n", 32 | "\n", 33 | "while True:\n", 34 | " rate,frame = cap.read()\n", 35 | " \n", 36 | " cv2.imshow('web_cam',frame)\n", 37 | "\n", 38 | " '''Press Q key for exit'''\n", 39 | " \n", 40 | " if cv2.waitKey(1) & 0xFF == ord('q'):\n", 41 | " break\n", 42 | " \n", 43 | "cap.release()\n", 44 | "cv2.destroyAllWindows()" 45 | ] 46 | } 47 | ], 48 | "metadata": { 49 | "kernelspec": { 50 | "display_name": "Python 3", 51 | "language": "python", 52 | "name": "python3" 53 | }, 54 | "language_info": { 55 | "codemirror_mode": { 56 | "name": "ipython", 57 | "version": 3 58 | }, 59 | "file_extension": ".py", 60 | "mimetype": "text/x-python", 61 | "name": "python", 62 | "nbconvert_exporter": "python", 63 | "pygments_lexer": "ipython3", 64 | "version": "3.7.0" 65 | } 66 | }, 67 | "nbformat": 4, 68 | "nbformat_minor": 4 69 | } 70 | -------------------------------------------------------------------------------- /using_USB/camera_input_from_Android.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "\n", 8 | "\n", 9 | "1. Download droidcam app on your Android device from [play store](https://play.google.com/store/apps/details?id=com.dev47apps.droidcam&hl=en_IN)\n", 10 | "\n", 11 | "2. Download and install [Dev47app](https://www.dev47apps.com/droidcam/windows/) setup on your pc.\n", 12 | "\n", 13 | "3. On the phone, go to Settings -> Developer Options, and enable “USB Debugging”. \n", 14 | " - (In case) On most phones the Developer options screen is hidden by default. To make it visible, go to Settings > About phone and tap “Build number” 7 times. Return to the previous screen to find “Developer options” at the bottom.\n", 15 | "\n", 16 | "4. Plug the device into computer over USB and open Droidcam app. \n", 17 | " - If you get a dialog on the phone asking “Allow USB Debugging”, you need to tap OK. \n", 18 | " - If you get dialog `Use USB for` When you plugged in, give permission to Photo transfer(PTP)\n", 19 | "\n", 20 | "5. open Droidcam app on pc and click on USB logo and press refreash button, you will get your device name or some random string(unique id). \n", 21 | "\n", 22 | "6. Add port which is showing in your mobile screen(generally 4747). \n", 23 | "\n", 24 | "7. Hit start button and you will get camera input on your computer screen.\n", 25 | "\n", 26 | "8. run below code and you will get your mobile camera input(make sure you installed all libraries using requirements.txt)." 27 | ] 28 | }, 29 | { 30 | "cell_type": "code", 31 | "execution_count": null, 32 | "metadata": {}, 33 | "outputs": [], 34 | "source": [ 35 | "import cv2\n", 36 | "\n", 37 | "cap = cv2.VideoCapture(1)\n", 38 | "'''if you get error instead of 1 try -1,2,3'''\n", 39 | "\n", 40 | "while True:\n", 41 | " rate,frame = cap.read()\n", 42 | " \n", 43 | " cv2.imshow('web_cam',frame)\n", 44 | "\n", 45 | " '''Press Q key for exit'''\n", 46 | " \n", 47 | " if cv2.waitKey(1) & 0xFF == ord('q'):\n", 48 | " break\n", 49 | " \n", 50 | "cap.release()\n", 51 | "cv2.destroyAllWindows()" 52 | ] 53 | } 54 | ], 55 | "metadata": { 56 | "kernelspec": { 57 | "display_name": "Python 3", 58 | "language": "python", 59 | "name": "python3" 60 | }, 61 | "language_info": { 62 | "codemirror_mode": { 63 | "name": "ipython", 64 | "version": 3 65 | }, 66 | "file_extension": ".py", 67 | "mimetype": "text/x-python", 68 | "name": "python", 69 | "nbconvert_exporter": "python", 70 | "pygments_lexer": "ipython3", 71 | "version": "3.7.0" 72 | } 73 | }, 74 | "nbformat": 4, 75 | "nbformat_minor": 4 76 | } -------------------------------------------------------------------------------- /using_wifi/take_mobile_camera_input_using_IPWebcam.ipynb: -------------------------------------------------------------------------------- 1 | { 2 | "cells": [ 3 | { 4 | "cell_type": "markdown", 5 | "metadata": {}, 6 | "source": [ 7 | "# Steps:\n", 8 | "\n", 9 | "* connect both mobile and computer with same **Internet**\n", 10 | " - If you have wifi than connect both computer and mobile with wifi\n", 11 | " - If you do not have wifi than turn on mobile hotspot and connect PC with it.\n", 12 | "* Open Ip Webcam app\n", 13 | "* scroll down to bottom than click on **start server** button\n", 14 | "* Now app establish local addresh " 15 | ] 16 | }, 17 | { 18 | "cell_type": "code", 19 | "execution_count": 1, 20 | "metadata": {}, 21 | "outputs": [], 22 | "source": [ 23 | "# shift + enter to import require library\n", 24 | "import os\n", 25 | "import cv2\n", 26 | "import numpy as np\n", 27 | "import requests" 28 | ] 29 | }, 30 | { 31 | "cell_type": "markdown", 32 | "metadata": {}, 33 | "source": [ 34 | "* Copy that address and add in below cell" 35 | ] 36 | }, 37 | { 38 | "cell_type": "code", 39 | "execution_count": 2, 40 | "metadata": {}, 41 | "outputs": [], 42 | "source": [ 43 | "port_address = 'http://192.168.43.1:8080//'#if you have different address than this than change" 44 | ] 45 | }, 46 | { 47 | "cell_type": "code", 48 | "execution_count": null, 49 | "metadata": {}, 50 | "outputs": [], 51 | "source": [] 52 | }, 53 | { 54 | "cell_type": "markdown", 55 | "metadata": {}, 56 | "source": [ 57 | "Choose your required image size here which save last frame to image when you press **Esc** key" 58 | ] 59 | }, 60 | { 61 | "cell_type": "code", 62 | "execution_count": 3, 63 | "metadata": {}, 64 | "outputs": [], 65 | "source": [ 66 | "img_width =512\n", 67 | "img_height = 512" 68 | ] 69 | }, 70 | { 71 | "cell_type": "markdown", 72 | "metadata": {}, 73 | "source": [ 74 | "Below written code will take frame from camera and will display it. when you press **Esc** key loop will break and only last frame will save as image.jpg" 75 | ] 76 | }, 77 | { 78 | "cell_type": "code", 79 | "execution_count": 4, 80 | "metadata": {}, 81 | "outputs": [], 82 | "source": [ 83 | "while True:\n", 84 | "\n", 85 | " img_req = requests.get(port_address + 'shot.jpg')\n", 86 | " img_arr = np.array(bytearray(img_req.content), dtype=np.uint8)\n", 87 | " img = cv2.imdecode(img_arr, -1)\n", 88 | " \n", 89 | " cv2.imshow('Mobile_cam', img)\n", 90 | " \n", 91 | " if cv2.waitKey(1) & 0xFF == 27:\n", 92 | " frame = cv2.resize(img,(img_width,img_height))\n", 93 | " cv2.imwrite('image.jpg', img)\n", 94 | " break\n", 95 | "\n", 96 | "\n", 97 | "cv2.destroyAllWindows()" 98 | ] 99 | }, 100 | { 101 | "cell_type": "markdown", 102 | "metadata": {}, 103 | "source": [ 104 | "Browse port address in web browser and explore more settings from there....\n", 105 | "LIKE\n", 106 | "* Change quality\n", 107 | "* zooming\n", 108 | "* flip camera(front/back)\n", 109 | "* horizontal/portrat\n", 110 | "\n", 111 | "And many more\n", 112 | "\n", 113 | "will update code for save video file........till enjoy!\n", 114 | "# Thank you:)" 115 | ] 116 | } 117 | ], 118 | "metadata": { 119 | "kernelspec": { 120 | "display_name": "Python 3", 121 | "language": "python", 122 | "name": "python3" 123 | }, 124 | "language_info": { 125 | "codemirror_mode": { 126 | "name": "ipython", 127 | "version": 3 128 | }, 129 | "file_extension": ".py", 130 | "mimetype": "text/x-python", 131 | "name": "python", 132 | "nbconvert_exporter": "python", 133 | "pygments_lexer": "ipython3", 134 | "version": "3.7.0" 135 | } 136 | }, 137 | "nbformat": 4, 138 | "nbformat_minor": 4 139 | } 140 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # connect_mobile_camera_with_computer_using_python 2 | Code regarding connect any android or Iphone mobile camera with computer for python and openCV. 3 | 4 | Some time you have to do live streaming or have to run object detection model with camera and you don't have high quality camera, well solution is here. 5 | 6 | # Setting up the repo:- 7 | Clone repo to your computer 8 | ``` 9 | git clone https://github.com/ravirajsinh45/connect_mobile_camera_with_computer_using_python.git 10 | ``` 11 | 12 | change directory 13 | ``` 14 | cd connect_mobile_camera_with_computer_using_python 15 | ``` 16 | 17 | Now install require libraries. 18 | ``` 19 | pip install -r requirements.txt 20 | ``` 21 | 22 | Their are two way to connect camera with pc 23 | 1. Using USB cable 24 | 2. Using WIFI 25 | 26 | 27 | # Steps Using USB:- 28 | 29 | ## For IOS device 30 | 31 | 32 | 1. Download Droidcam app on your IOS device from [app store](https://apps.apple.com/us/app/droidcam-wireless-webcam/id1510258102) 33 | ![](https://github.com/ravirajsinh45/connect_mobile_camera_with_computer_using_python/blob/master/images/app_store.jpeg) 34 | 35 | 2. Download and install [Dev47app](https://www.dev47apps.com/droidcam/windows/) setup on your pc for ios devices. 36 | 37 | 3. Plug the device with PC and open Droidcam on your iphone you will get screen like this ![](https://github.com/ravirajsinh45/connect_mobile_camera_with_computer_using_python/blob/master/images/app_screen.jpeg) 38 | 39 | 4. open Droidcam app on pc and click on USB button, you will get screen like this ![](https://github.com/ravirajsinh45/connect_mobile_camera_with_computer_using_python/blob/master/images/pc_screen_of_droidcam_client.jpg) 40 | 41 | 5. Hit first refresh button and will get your device id in box than after hit start button and you will get camera input on your computer screen. 42 | 43 | 6. From using_USB folder open [camera_input_for_IOS_device](https://github.com/ravirajsinh45/connect_mobile_camera_with_computer_using_python/blob/master/using_USB/camera_input_from_IOS_devices.ipynb) and run the code. 44 | 45 | ## For Android device 46 | here is documantation by [Droidcam](https://www.dev47apps.com/droidcam/connect/) 47 | 48 | 49 | 1. Download droidcam app on your Android device from [play store](https://play.google.com/store/apps/details?id=com.dev47apps.droidcam&hl=en_IN) 50 | ![](https://github.com/ravirajsinh45/connect_mobile_camera_with_computer_using_python/blob/master/images/play_store.jpeg) 51 | 52 | 2. Download and install [Dev47app](https://www.dev47apps.com/droidcam/windows/) setup on your pc. 53 | 54 | 3. On the phone, go to Settings -> Developer Options, and enable “USB Debugging”. 55 | - (In case) On most phones the Developer options screen is hidden by default. To make it visible, go to Settings > About phone and tap “Build number” 7 times. Return to the previous screen to find “Developer options” at the bottom. 56 | 57 | 4. Plug the device into computer over USB and open Droidcam app. 58 | - If you get a dialog on the phone asking “Allow USB Debugging”, you need to tap OK. 59 | - If you get dialog `Use USB for` When you plugged in, give permission for Photo transfer(PTP) 60 | ![](https://github.com/ravirajsinh45/connect_mobile_camera_with_computer_using_python/blob/master/images/android_screen.jpeg) 61 | 62 | 5. open Droidcam app on pc and click on USB logo and press refreash button, you will get your device name or some random string(unique id). 63 | 64 | 6. Add port which is showing in your mobile screen(generally 4747). 65 | 66 | 7. Hit start button and you will get camera input on your computer screen. 67 | 68 | 8. Open [this notebook](https://github.com/ravirajsinh45/connect_mobile_camera_with_computer_using_python/blob/master/using_USB/camera_input_from_Android.ipynb) run the code and you will get your mobile camera input(make sure you installed all libraries using requirements.txt). 69 | 70 | 71 | # Steps Using Wifi 72 | 73 | ## For Android devices 74 | ### Using IP Webcam app 75 | 1. Download IP Webcam application from [play store](https://play.google.com/store/apps/details?id=com.pas.webcam&hl=en_IN) 76 | 77 | 2. connect both mobile and computer with same **Internet** 78 | - If you have wifi than connect both computer and mobile with wifi 79 | - If you do not have wifi than turn on mobile hotspot and connect PC with it. 80 | 81 | 3. Open Ip Webcam app 82 | 83 | 4. scroll down to bottom than click on **start server** button 84 | 85 | 5. From `using_wifi` folder open [this notebook](https://github.com/ravirajsinh45/connect_mobile_camera_with_computer_using_python/blob/master/using_wifi/take_mobile_camera_input_using_IPWebcam.ipynb) and follow along. 86 | 87 | ## For Ios devices 88 | ### Using Droidcam app 89 | Update soon 90 | 91 | 92 | 93 | 94 | # Thank you:) 95 | 96 | --------------------------------------------------------------------------------