Python+opencv+android mobile phone as IP camera on Ubuntu

Source: Internet
Author: User
Tags get ip python script

What to do without a USB camera.

It's okay to have an Android phone, we can turn it into a webcam.

1. Install a mobile phone called [IP Camera] app, get IP address, account password

2. Install Python and OpenCV

3. Execute the Python script below, and notice that you want to change the IP address to the one displayed on your phone.

#coding =utf-8
Import CV2.CV as CV

import time

if __name__ = ' __main__ ':

    cv. Namedwindow ("Camera", 1)
    #开启ip摄像头
    video= "http://admin:admin@192.168.0.123:8081/"
    capture =CV. Capturefromfile (VIDEO)
  
    num = 0;
    While True:
        img = cv. Queryframe (Capture)
        CV. ShowImage ("Camera", IMG)

	#按键处理, note that the focus should be in the camera window, not in the Terminal Command Line window
        key = CV. Waitkey (a) 

        if key = =
	    #esc键退出
	    print "Esc break ..." Break
        if key = = Ord ('):
             #保存一张图像 C19/>num = num+1
            filename = "frames_%s.jpg"% num
            cv. SaveImage (filename,img)


    del (capture)
    CV. DestroyWindow ("Camera")

Run the APP:IP camera on the phone first, click on the button at the bottom [turn the device into an IP camera],

Then run the python script in Ubuntu, wait a few seconds, and you'll see the camera content.




Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.