I'm struggling to get opencv2 to work with my NOIR camera board.
I'm following this guide to make the pi camera work with the opencv2, but don't fully understand what it's doing, and can not get it working with a python file below.
#!/usr/bin/env python
import cv2
# Camera 0 is the integrated web cam on my netbook
camera_port = 0
#Number of frames to throw away while the camera adjusts to light levels
ramp_frames = 60
# Now we can initialize the camera capture object with the cv2.VideoCapture class.
# All it needs is the index to a camera port.
camera = cv2.VideoCapture(camera_port)
# Captures a single image from the camera and returns it in PIL format
def get_image():
# read is the easiest way to get a full image out of a VideoCapture object.
retval, im = camera.read()
return im
# Ramp the camera - these frames will be discarded and are only used to allow v4l2
# to adjust light levels, if necessary
for i in xrange(ramp_frames):
temp = get_image()
print("Taking image...")
# Take the actual image we want to keep
camera_capture = get_image()
file = "test_image_1_from_open_cv2.jpg"
# A nice feature of the imwrite method is that it will automatically choose the
# correct format based on the file extension you provide. Convenient!
cv2.imwrite(file, camera_capture)
# You'll want to release the camera, otherwise you won't be able to create a new
# capture object until your script exits
del(camera)
When run, the python file doesn't throw up any errors, but returns an empty jpg. The python code works on my PC, but not on my PI.
This leads me to think its how opencv links to the camera board, that's the problem.
As far as I understand it, the above guide instructs us to search through "C files that opencv might use, like raspistill" then re-compiles them to work with the camera board.
It does this by searching, and replacing, using the command sed -i ‘s/if (DEFINED CMAKE_TOOLCHAIN_FILE)/if (NOT DEFINED CMAKE_TOOLCHAIN_FILE)/g’ makefiles/cmake/arm-linux.cmake
The search criteria has been kindly explained here, but could someone please explain
1) What I need to do with the compiled versions of say raspistill. it's currently in /opt/vc/build/bin
2) If there are 2 raspistills on my PI how does the PI know which one to use?
sudo /etc/init.d/motion stop
then running the above script from the directory the script is located/usr/src/scripts
and by running using the commandsudo ./videocaprure_opencv2.py
BUT the resultant image is tiny! Why?