Getting Python input from Webcam on raspberry pi? - python

i'm using a sony ps3 eye as webcam input on my pi for an OpenCL python program I'm writing, but for some reason no matter what i do the pi python compiler isn't accessing the webcam. Yet the same code when run on my laptop using the same webcam runs perfectly. Then i checked the usb devices on my pi and it state that "sony playstation 3 eye cam" was on usb port 6. also when using the "motion" package on the pi i was able to use the camera perfectly as input. So my problem is again that the python compiler isn't communicating with my webcam on the pi. Please, think about this and tell me how to fix it; i simply can't think of what's wrong. Here's the sample code I used, and please help me out. Thank you very much.
import cv2.cv as cv
#cv.NamedWindow("w1", cv.CV_WINDOW_AUTOSIZE)
camera_index = 0
capture = cv.CaptureFromCAM(camera_index)
while not capture:
print "error opening capture device, correction attempt"
while True:
frame = cv.QueryFrame(capture)
if frame is None:
print "fail with putting in frame"
else:
c = cv.WaitKey(100)
print 'capturing!'
cv.SaveImage("pictest.png", frame)

I never updated this but my solution was: I used the Motion Package for Raspberry Pi to receive images (since the Sony Ps3 EyeToy Camera did not have drivers written that were compatible with the Pi) and then Used OpenCV to analyze each Image. Doing this as each image came in, many times a second, is the same as analyzing video through OpenCV.This implementation worked perfectly for my needs, and I used other Bash tools to delete old image files after a certain time period so my memory was not unnecessarily filled.

There are some known problems with isochronous USB. Some camera issues have been addressed with recent fixes, but others remain (and apparently being worked upon). What kernel version are you using (uname -a)?
The fixes have not worked their way into the official distribution yet, so if you don't want to wait can run rpi-update to pick up the latest kernel (assuming you're using Raspbian). You want at least #389.

Related

Python OpenCV with Imaging device USB3 Vision compliant camera - VideoCapture() index of camera not found

I have a problem with using external camera in Python OpenCV.
I am using Windows.
In device manager, camera is not under "Cameras", but under "Imaging devices" and is called USB3 Vision compliant camera.
The camera is working fine on app given by company (UcamViewer).
I want to connect to this camera using cv2.VideoCapture().
I have of course tried:
cv2.VideoCapture(k)
for k = [0..100]
Only k = 0 is occupied and works - that is my webcam.
I have also tried adding multiple possible values to the second parameter of the VideoCapture(), which did not work.
how to get video from a "USB3 Vision" device?
This question suggested to use cv.CAP_XIMEA as the second parameter of VideoCapture(), but CAP_XIMEA does not seem to be a possible value.
If I can not fix this issue and use VideoCapture(), what would you suggest to use to capture the video and convert it to format that can be used by openCV methods?
Any ideas how could I solve this issue will be appreciated.
Thank you for your help.

How to select a different webcam using cv2 in python

I am trying to stream live video from an external camera using cv2. I was able to write the simple code to stitch the frames and stream it. But am struggling to find how to change the camera.
I tried to run it after disabling the main webcam from the task manager, but it still did not work.
So, if anyone can help me with some clue regarding the same, that would be a great help.
Cameras are numbered for Windows. You can try a few indeces and check which camera index belongs to the camera you want.
capture = cv2.VideoCapture(index)

OpenCV connection ps3 eye camera (python)

Heading I need to get an image at the same time (almost, it is possible to take turns in a loop) from two PS3 Eye cameras, and then work with them using OpenCV.
We need drivers for the ps3 eye multicam (for example, these are not suitable https://codelaboratories.com/downloads/)
As an option for drivers there is a program zadig(https://zadig.akeo.ie/), and in particular WinUSB (libusb), but OpenCV Python (the standard function cv2.VideoCapture) sees only one camera. I found a project that can use several cameras at once in OpenCV with WinUSB drivers (libusb) - https://github.com/psmoveservice/PSMoveService/releases (Open bin/test_camera.exe). But it is written in C++ and due to its incompetence in this programming language, I could not port the code to python.
In the end, I need drivers and Python code to use the ps3 eye multicam in OpenCV.
Try checking this. Get the environment you want to build.
https://github.com/bensondaled/pseyepy
Let's you configure the camera as well.

How to load video with opencv-python on Windows machine? (Difference btw Windows / Linux ?)

I am new to the opencv(3.0.0)-python(2.7).
There is an error with loading the video on a windows machine with cv2.Videocapture. I actually tried to use haar classifier using the video, but since the video file wasn't playing I tried the following simple code.
import cv2
cap = cv2.VideoCapture('‪C:\\Users\\jimmy\\Desktop\\bbd.mp4')
if cap.isOpened():
print 'Yes'
else:
print 'No'
And it keeps returning 'No'.
I don't think it's the problem of directory because it worked perfectly with images and imshow, imread functions. So, these kinds of errors always happen when I try to load a video.
I actually used raspberrypi to load a video before and it worked perfectly, so I am wondering is there any difference between rpi and windows machine that I don't know. Also please tell me how to fix it.
Thanks in advance !
Change your path from this:
cap = cv2.VideoCapture('‪C:\\Users\\jimmy\\Desktop\\bbd.mp4')
to this
cap = cv2.VideoCapture('‪C:/Users/jimmy/Desktop/bbd.mp4')
OpenCV doesn't like the forward slashes for some reason

Python Wifi Issue Connect to Mysterious Camera

I have been working with some drones and robotics projects using arduino and python. There was a kickstarter project for a neat little hex copter, that hasn't been managed well.
I was lucky, i got my copter and then some time later after some frustrated email exchanges, i finally recieved the camera as well. To this day, their forum has people still complaining. Their maker forum is now down and their wiki hasn't been updated with any specifics on the camera.
http://www.flexbot.cc/wiki/index.php?title=Main_Page#Hardware
Their app to accompany the drone still doesn't support the camera module. Not that it'd matter, as their code isn't very well documented or annotated.
https://github.com/HexAirbot
There are some tips on switching the camera on the comments page of their kickstarter campaign.
https://www.kickstarter.com/projects/1387330585/hex-a-copter-that-anyone-can-fly/posts/1093716
So, sob story over, i'm stuck with this neat little wifi camera that i am unsure on how to connect to. I know how to switch it on and it does have a micro-usb port on it.
What library in Python could i use to stream an image from this camera given that it is a wifi camera. If i wanted the video stream as a numpy matrix.
I need to interface with the camera, so i can connect and disconnect.
Then, be able to read images frame by frame with ffmpeg. I have some python modules that can detect and read from a camera, but how can my code ensure that the camera is connected?
Totally stuck. Any help would be appreciated.
Considering you are building for the android platform, you will more than likely need to use some sort of java/python driver/interface, unless you just use java.
Here is an article on java/python, and using python from within java.
Using Python from within Java

Categories

Resources