[EV3 x Python] Stream the camera image to your PC using mjpg-streamer.

Overview

I will introduce the procedure to stream the camera image from ev3 using mjpg-streamer. With ev3dev, you can set up a streaming server just by installing the software. Create a code to display the video using OpenCV on the PC side.

Premise

Install MJPG-streamer

I use apt-get to install MJPG-streamer, but please create a swap area in advance because it may fail due to insufficient memory with the default settings. Please refer to this article to create the method! [EV3 x Python] How to create a swap area

If you don't know how to open the terminal in the first place ↓ [EV3 x Python] SSH connection

Enter from the following command in the terminal. When asked for the password, maker

$ cd ~
$ sudo apt-get install -y cmake libv4l-dev libjpeg-dev imagemagick
$ git clone https://github.com/jacksonliam/mjpg-streamer.git
$ cd mjpg-streamer/mjpg-streamer-experimental
$ make
$ sudo make install 

Run MJPG-streamer

$ cd ~/mjpg-streamer/mjpg-streamer-experimental/
$ ./mjpg_streamer -o "output_http.so -w ./www" -i "input_uvc.so"

Images are displayed when accessing ev3 with a PC browser

If you access http://ev3dev.local:8080 with the browser of the PC to which EV3 is connected, the streaming page will open. スクリーンショット 2020-01-14 2.38.12.png I'm sorry in a dirty room w

Create a script to project images in Python

streaming.py


from cv2.cv2 import VideoCapture,waitKey,imshow,destroyAllWindows

#Specify the link to which the video will be sent.
cap = VideoCapture("http://ev3dev.local:8080/?action=stream")

#If the link cannot be opened
if not cap.isOpened():
    print("Cannot open a video capture.")
    exit(-1)


while True:
    #Loop ends when esc key is pressed
    k = waitKey(1)

    if k == 27:
        break

    #Get the frame of the incoming video
    ret, frame = cap.read()
    
    #If the frame could not be obtained
    if not ret:
        continue

    #Show frame
    imshow("EV3 Streaming", frame)

#Opening the capture&close the window
cap.release()
destroyAllWindows()

Execution result

スクリーンショット 2020-01-14 2.42.58.png ** Sorry for the dirty room m (_ _) m **

Recommended Posts

[EV3 x Python] Stream the camera image to your PC using mjpg-streamer.
Try to log in to Netflix automatically using python on your PC
[Python] I tried to judge the member image of the idol group using Keras
[Circuit x Python] How to find the transfer function of a circuit using Lcapy
Excel X Python The fastest way to work
[Algorithm x Python] How to use the list
Save your heart rate to SpreadSheets in real time (?) Using Python x fitbit API!
Steps to install the latest Python on your Mac
Convert the image in .zip to PDF with Python
Write data to KINTONE using the Python requests module
Post to your account using the API on Twitter
[Python] Mask the image into a circle using Pillow
[Introduction to Python] How to stop the loop using break?
Python OpenCV tried to display the image in text.
I tried to compress the image using machine learning
[python] Change the image file name to a serial number
[Circuit x Python] How to solve circuit equations symbolically using sympy
Try a similar search for Image Search using the Python SDK [Search]
Connect to the Bitcoin network using pycoin (Python Cryptocoin Utili)
Tweet Now Playing to Twitter using the Spotify API. [Python]
Operate your browser using the Selenium Web Driver Python bindings
Shoot time-lapse from a PC camera using Python and OpenCV
Dot according to the image
Post to Twitter using Python
Start to Selenium using python
Convert python 3.x code to python 2.x
Do a search by image from the camera roll using Pythonista3
Posture detection by openpose from USB camera image using python code
Display the image of the camera connected to the personal computer on the GUI.
[Python] Try to graph from the image of Ring Fit [OCR]
How to get followers and followers from python using the Mastodon API
Try to edit a new image using the trained StyleGAN2 model
I just erased the object using image repair (inpaint) (OpenCV: Python)
[Circuit x Python] How to enable the linear circuit analysis package Lcapy
The road to installing Python and Flask on an offline PC
Regularly upload files to Google Drive using the Google Drive API in Python
The fastest way to get camera images regularly with python opencv