Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using a USB camera? #193

Closed
Ericktz opened this issue Feb 7, 2017 · 8 comments
Closed

Using a USB camera? #193

Ericktz opened this issue Feb 7, 2017 · 8 comments

Comments

@Ericktz
Copy link
Contributor

Ericktz commented Feb 7, 2017

Hi, well this is an only question or suggestion if is not possible. Can I use a USB camera instead of a Picamera???

@kizniche
Copy link
Owner

kizniche commented Feb 7, 2017

It depends on what you would like to do with it. I'm open to suggestions. Do you have a specific use in mind?

@Ericktz
Copy link
Contributor Author

Ericktz commented Feb 7, 2017

I would think for the moment only as a follow-up for an indoor crop, or as an outdoor security camera. Not everyone has a Pi camera, and the USB camera also it is more accessible and cheaper.

@kizniche
Copy link
Owner

kizniche commented Feb 7, 2017

The nice thing about the Pi camera is it's guaranteed to work because the hardware is standardized. Mycodo uses the python module, picamera.

USB cameras are pretty variable in how to acquire images from them. I haven't really explored using them with Mycodo, but I would give it a try. If there's a universal python module that can detect/acquire from USB cameras, this would be rather easy to integrate into Mycodo. I'm not sure if this exists or not, I haven't really looked.

As of how, if you want to do time-lapses, the easiest way is to write a script and add it to cron.

From within Mycodo, you can trigger still image captures from relay/sensor/PID conditional statements by creating a script that captures an image, then use the 'execute command' option in the conditional. So, when your conditional is triggered, the script is executed and the image acquired.

I believe there is also some good software for the Pi that can turn it into a security camera, and I believe it allows the use of USB cameras. These software that allow USB cameras may also be a good place to look how they acquire images from the USB camera, for possible use within Mycodo.

@kizniche
Copy link
Owner

I just tested my webcam with opencv, and I was able to get an image right away! Very promising!

@kizniche
Copy link
Owner

kizniche commented Feb 10, 2017

You can try the new script I pushed, test_camera_capture_still.py, by saving it and running the following:

sudo apt-get install python-opencv
python test_camera_capture_still.py

An image 'camera_image_[timestamp].bmp' will be created if it successfully detects a camera.

If you have multiple cameras connected to your Pi, you can change the device by altering Line 29 to a different integer greater than 0:

 cap = cv2.VideoCapture(0)

Let me know if it works for you and I'll look into ways to integrate the code into mycodo.

@Ericktz
Copy link
Contributor Author

Ericktz commented Feb 10, 2017

thank Kyle for trying this... it is work, an image was created with the name you wrote, but I give the following errror:

pi@raspi:~$ python test_camera_capture_still.py 
HIGHGUI ERROR: V4L2: Unable to get property <unknown property string>(0) - Invalid argument
('Test: ', -1.0)
HIGHGUI ERROR: V4L2: Unable to get property <unknown property string>(2) - Invalid argument
('Ratio: ', -1.0)
HIGHGUI ERROR: V4L2: Unable to get property <unknown property string>(5) - Invalid argument
('Frame Rate: ', -1.0)
('Height: ', 640.0)
('Width: ', 480.0)
('Brightness: ', 0.4577777683734894)
('Contrast: ', 0.5)
('Saturation: ', 0.41499999165534973)
HIGHGUI ERROR: V4L2: Unable to get property Hue(9963779) - Invalid argument
('Hue: ', 0.0)
HIGHGUI ERROR: V4L2: Unable to get property Gain(9963795) - Invalid argument
HIGHGUI ERROR: V4L: Gain control in V4L is not supported
('Gain: ', -1.0)
HIGHGUI ERROR: V4L2: Unable to get property Exposure(9963793) - Invalid argument
HIGHGUI ERROR: V4L: Exposure control in V4L is not supported
('Exposure: ', -1.0) 

@kizniche
Copy link
Owner

I've got a whole new camera system working in the dev-5.0 branch, with USB cameras working with opencv. When I release 5.0.0, you'll be able to test it out.

@Myke974
Copy link

Myke974 commented Feb 12, 2017 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants