Python and a UV4l trying to access camera module together
Posted: Sat May 02, 2015 11:32 am
I'm trying to use an opencv2 python script and UV4l-server to stream a live feed, from a NOIR camera board on my PI, but am running into problems.
The python script runs and displays the window, but I'm not getting the stream.
I'm sure the UV4l server is running, as it prompts me for a password, and I get the control panel, but the link http://myipaddress:8080/stream doesn't work; it gives an an empty window stating "image".
I also have Motion installed on the same PI using the camera, so have to stop it first.
I can get the stream working if i kill the UV4l process and run the command:
But can I have the script and a server trying to access the camera module at the same time and if not, how can I stream from inside an opencv2 python script?
The script:
The Warnings:
the Errors:
The python script runs and displays the window, but I'm not getting the stream.
I'm sure the UV4l server is running, as it prompts me for a password, and I get the control panel, but the link http://myipaddress:8080/stream doesn't work; it gives an an empty window stating "image".
I also have Motion installed on the same PI using the camera, so have to stop it first.
I can get the stream working if i kill the UV4l process and run the command:
Code: Select all
os.system("sudo uv4l --auto-video_nr --width 800 --height 600 --rotation 180 --framerate 2 --driver raspicam --encoding mjpeg --server-option '--admin-password=pw' --server-option '--user-password=pw'")
The script:
Code: Select all
#!/usr/bin/env python
import numpy as np
import cv2
import os
os.system('sudo /etc/init.d/motion stop') #to stop any conflict of motion using camera module
os.system ('sudo pkill uv4l')
os.system("sudo uv4l --auto-video_nr --width 800 --height 600 --rotation 180 --framerate 2 --driver raspicam --encoding mjpeg --server-option '--admin-password=pw' --server-option '--user-password=pw'")
runtime_frame_count = 0
vid = cv2.VideoCapture(0)
vid.set(3,800)
vid.set(4,600)
while True:
ret, img = vid.read()
runtime_frame_count = runtime_frame_count + 1
print (runtime_frame_count)
cv2.imshow("input",img)
key = cv2.waitKey(10)
key = cv2.waitKey(10)
key = cv2.waitKey(10)
if (key == 27) or (runtime_frame_count == 100):
break
cv2.destroyAllWindows()
cv2.VideoCapture(0).release()
Code: Select all
<notice> [core] Trying driver 'raspicam' from built-in drivers...
<warning> [core] Driver 'raspicam' not found
<notice> [core] Trying driver 'raspicam' from external plug-in's...
<notice> [driver] Dual Raspicam Video4Linux2 Driver v1.9.26 built Feb 10 2015
<notice> [driver] Selected format: 800x600, encoding: mjpeg, JPEG Video Capture
<notice> [driver] Framerate max. 2 fps
<notice> [driver] ROI: 0, 0, 1, 1
<notice> [core] Device detected!
<warning> [core] Cannot create /dev/video0 because file already exists
<notice> [core] Registering device node /dev/video1
libv4l2: error setting pixformat: Device or resource busy
HIGHGUI ERROR: libv4l unable to ioctl S_FMT