Movatterモバイル変換


[0]ホーム

URL:


Open In App
Next Article:
Determine The Face Tilt Using OpenCV - Python
Next article icon

Prerequisites:OpenCV

OpenCV is a huge open-source library for computer vision, machine learning, and image processing. OpenCV supports a wide variety of programming languages like Python, C++, Java, etc. It can process images and videos to identify objects, faces, or even the handwriting of a human. 

Many a time, while doing Computer Vision or Image Processing using our PC's webcam is not a very option. Maybe we want to increase the camera quality of our webcam, or we want to create some image processing applications which will use an android camera as the medium. 

This article uses Windows to do this. But the basics of the code will be same on other Operating systems too.

Approach

  • Download and installIP Webcam application on your mobile phone.
  • Then make sure your PC and Phone both are connected to the same network. Open your IP Webcam application on your both, click "Start Server" (usually found at the bottom). This will open a camera on your Phone.
  • A URL is being displayed on the Phone screen, type the same URL on your PC browser, and under "Video renderer" Section, click on "Javascript".
  • You can see video captured on your phone, which starts showing up on your browser. Now, what we will be going to do is, taking image data from the URL using the request module and convert this to an image frame using NumPy, and finally, start using our Android camera as a webcam in Python.
  • In the code:
    • Import module
    • Add URL displayed in your phone
    • Continuous fetch data from URL
    • Keep displaying this data collected
    • Close window

Program:

Python3
# Import essential librariesimportrequestsimportcv2importnumpyasnpimportimutils# Replace the below URL with your own. Make sure to add "/shot.jpg" at last.url="http://192.168.0.103:8080/shot.jpg"# While loop to continuously fetching data from the UrlwhileTrue:img_resp=requests.get(url)img_arr=np.array(bytearray(img_resp.content),dtype=np.uint8)img=cv2.imdecode(img_arr,-1)img=imutils.resize(img,width=1000,height=1800)cv2.imshow("Android_cam",img)# Press Esc key to exitifcv2.waitKey(1)==27:breakcv2.destroyAllWindows()

Output:


Similar Reads

We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood ourCookie Policy &Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences

[8]ページ先頭

©2009-2025 Movatter.jp