-
-
Notifications
You must be signed in to change notification settings - Fork 257
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
Camera_num option in PiCamera #64
Comments
@deepav-ai Thank you for following the issue template and bringing this idea up, I didn't know about this Picamera feature until now and surely this will be a nice addition to VidGear.
For now
Yes according to my tests, PiGear can work at full 1080p at 60fps as of now, but it will be a bit challenging to extend it to two cameras and sync them but it is certainly possible as it is already done in CamGear API. Kindly wait till I push the next PR related to this feature in the upcoming few days tackling these challenges. Then I'll be asking you to test it. Good luck! |
https://picamera.readthedocs.io/en/release-1.13/api_camera.html#picamera camera_num = 0 or 1. Previously when I created two PiCamera objects and had one as camera_num=0 and the other as camera_num=1 and set both to 1920x1080 30FPS it recorded both with no problem performance wise, just the sync was off when verified by recording a stop watch. |
I think we need to do syncing at the software side as Raspberry Pi is not powerful enough to make it possible at hardware end due to limited RAM & GPU shared memory. I'm thinking that We can release different camera frames at the same timestamp with VidGear's queue structure currently employed in CamGear API to achieve syncing virtually without any extra overhead. Let's try this approach out and see if it is possible. How much tolerance in timing between two camera frames is acceptable at your end, Or you looking for exact match? |
@deepav-ai I think picamera library does support resolution over 640x480, the thing is that the resolution of the final image we get from stereoscopic mode is the same as the given (or default) resolution parameter, and if a regular 4/3 ratio is given, the two images will be halved so that their combination fits into a 4/3 image. For example, to get one stereo image with two full (480x320) images inside, I have to use something like this : This is described in their docs: The stereo_mode parameter defaults to 'none' (no stereoscopic mode) but can be set to 'side-by-side' or 'top-bottom' to activate a stereoscopic mode. If the stereo_decimate parameter is True, the resolution of the two cameras will be halved so that the resulting image has the same dimensions as if stereoscopic mode were not being used. |
I'm using the StereoPI (RPI compute module with 2 CSI inputs) from the user in that post. When I try 640x480 it will output a file that is 1280x480 SBS. If I try 1280x720 in each camera to get 2560x720 it doesn't work. Here's a thread I opened on it, realizator/stereopi-tutorial#7 I don't really want SBS, two separate videos is better because this will go through a machine learning workflow as separate feeds. |
For your question on tolerance, I'm not sure yet but this is video footage from a car going highway speeds so it's likely pretty sensitive to sync. |
@deepav-ai You are interpreting this wrong. In your dual camera setup on your Compute module with Picamera library, You only need to specify your final stereoscopic image size in the resolution parameter such as
@deepav-ai Yes I'm working on it and very shortly I'm pushing a PullRequest related to this, Kindly stay tuned and ready to test it. |
- added new `camera_num` to support multiple Picameras(#64) - moved thread exceptions to main thread and then re-raised(#61) - added new threaded timeout function to handle any hardware failures/frozen threads(#61) - PiGear will not exit safely if Picamera ribbon cable is pulled out to save resources - Minor tweaks for more robust overall error handling.
Hello @deepav-ai, Kindly install the related PR(#67) as follows: git clone https://github.com/abhiTronix/vidgear.git
cd vidgear
git checkout development
sudo pip3 install .
cd I've added the Test syncing:To test sync between two cameras use following code (:warning: Remember to keep all parameter except # import required libraries
from vidgear.gears import PiGear
import cv2
import time
#Remember to keep all parameter except `camera_num` similar in both following Cameras streams
# define and start the stream on first source ( For e.g #0 index Picamera)
stream1 = PiGear(camera_num=0, resolution=(640, 480), framerate=30, logging=True).start()
# define and start the stream on second source ( For e.g #1 index Picamera)
stream2 = PiGear(camera_num=1, resolution=(640, 480), framerate=30, logging=True).start()
# infinite loop
while True:
frameA = stream1.read()
# read frames from stream1
frameB = stream2.read()
# read frames from stream2
# check if any of two frame is None
if frameA is None or frameB is None:
#if True break the infinite loop
break
# do something with both frameA and frameB here
cv2.imshow("Output Frame1", frameA)
cv2.imshow("Output Frame2", frameB)
# Show output window of stream1 and stream 2 seperately
key = cv2.waitKey(1) & 0xFF
# check for 'q' key-press
if key == ord("q"):
#if 'q' key-pressed break out
break
if key == ord("w"):
#if 'w' key-pressed save both frameA and frameB at same time
cv2.imwrite("Image-1.jpg", frameA)
cv2.imwrite("Image-2.jpg", frameB)
#break #uncomment this line to break out after taking images
cv2.destroyAllWindows()
# close output window
# safely close both video streams
stream1.stop()
stream2.stop() While running above code, To confirm syncing press Also don't forget to go through the PR, to see what has changed. Good luck. |
I ran the exact commands you posted and the code. I then did a fresh reboot. pi@raspberrypi:~/Documents/Embedded-Python $ python record-stereo2.py |
but it should be @deepav-ai this line means you're still using old vidgear binaries. This happens when you have multiple python version on your machine, Kindly clean reinstall vidgear as follows: ( makedir - p installdir && cd installdir
sudo pip uninstall vidgear
git clone https://github.com/abhiTronix/vidgear.git
cd vidgear
git checkout development
sudo python -m pip install .
cd
@deepav-ai This lines Clearly means you're NOT using the exactly the same above code that I provided to test syncing between two cameras. See code in my comment above:
Either another python script you used recently using this camera (Can be solved by Restarting your Pi) or it means the CSI port failed to enable since the GPU memory is not enough. Kindly increase you GPU memory by changing |
pi@raspberrypi:~/Documents/installdir/vidgear $ sudo python -m pip install . No matching distribution found for opencv-contrib-python (from vidgear==0.1.6.dev0) |
@deepav-ai paste the output of following command from your Pi terminal: sudo python -c "import platform; print(platform.python_version())" and also try running above code for syncing with command |
2.7.16.
I changed to gpu_mem=256 and rebooted. I've checked the cameras with the standard Picamera script and they work.
|
@deepav-ai There's a complete mess with python paths and pip on your Pi. There are surprisingly three different python3 modules directories on your computer, one is newer python 3.7.3(located at Kindly paste output of following commands: which python
which python3
which python37
python -c "import site;print(site.getsitepackages())"
python -c "import site;print(site.getusersitepackages())"
python3 -c "import site;print(site.getsitepackages())"
python3 -c "import site;print(site.getusersitepackages())"
sudo python3 -c "import site;print(site.getsitepackages())"
sudo python3 -c "import site;print(site.getusersitepackages())" |
Here's what I get if I run these commands |
@deepav-ai Thanks, Python is working as expected but Pip not. I'll advise to completely remove both distro pip as follows(if present): sudo apt purge python-pip
sudo apt purge python3-pip and then install the official pip as follows: curl https://bootstrap.pypa.io/get-pip.py -o get-pip.py
python get-pip.py
python3 get-pip.py and then install vidgear as previous:
and test above given code with |
This comment has been minimized.
This comment has been minimized.
@deepav-ai I'm merging the PR now as it performed as expected at my end, Kindly share your results when you're ready. Good luck! |
Major Updates and BugFixes for PiGear - added new camera_num to support multiple Picameras(#64) - moved thread exceptions to the main thread and then re-raised(#61) - replaced traceback with sys.exc_info. - added new threaded internal timing function to handle any hardware failures/frozen threads(#61) - PiGear will not exit safely with SystemError if Picamera ribbon cable is pulled out to save resources. - added support for new user-defined HWFAILURE_TIMEOUT options attribute to alter timeout. - Minor tweaks for more robust overall error handling.
Ran the exact commands you listed above.
|
Means you're still somehow using the old vidgear library binaries. It's clear the problem of incorrect python packages(pip) paths on your pi and is beyond the scope of issue, Kindly fix this on your own end. If possible, test this library on a Fresh Raspbian Stretch/Buster OS and it must work, if it doesn't then report here. |
Question
I'm using a Raspberry Pi Compute module with two RPI cameras. I'm using the example code for the Raspberry Pi camera and I'm trying to use the camera_num option from here:
class picamera.PiCamera(camera_num=0, stereo_mode='none', stereo_decimate=False, resolution=None, framerate=None, sensor_mode=0, led_pin=None, clock_mode='reset', framerate_range=None)
I tried putting it in
stream = PiGear(camera_num=1, resolution=...
and also in the options string but both times it says
'PiCamera' object has no attribute 'camera_num'.
Is this supported? If I use the PiCamera module directly this works.
Acknowledgment
Context
I'm trying to synchronize the two Raspberry Pi Cameras. If I use PiCamera library and thread them they are still slightly out of sync. I'm hoping to use this library to simply write a timestamp to a log file for each video and then I'll attempt to sync them offline. The built in stereoscopic option in the PiCamera library doesn't support anything over about 640x480 and I'm looking to record at 1920x1080 on each camera.
Your Environment
Optional
The text was updated successfully, but these errors were encountered: