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.
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
$ cd ~/mjpg-streamer/mjpg-streamer-experimental/
$ ./mjpg_streamer -o "output_http.so -w ./www" -i "input_uvc.so"
If you access http://ev3dev.local:8080 with the browser of the PC to which EV3 is connected, the streaming page will open. I'm sorry in a dirty room w
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()
Recommended Posts