1

I'm using opencv2 and V4L2 driver on my pi and have managed to get a tiny picture out of the Raspberry Pi Camera Module with the following script:

#!/usr/bin/env python

import cv2


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)

I run the script from the directory that it's located by:

sudo ./videocaprure_opencv2.py

But the image is tiny!

How can I get a normal size picture?

reggie
  • 1,121
  • 4
  • 14
  • 30
  • I don't think opencv is using the v4l2 driver because when I do sudo service uv4l_raspicam stop and sudo ./videocaprure_opencv2.py the script still puts out a tiny image. followed by 14 lines of VIDIOC_QUERYMENU: Invalid argument – reggie Feb 23 '15 at 15:20
  • when i sudo service uv4l_raspicam start it prints out lots of lines of info but one is of interest <notice> [core] Registering device node /dev/video1, so I then do sudo dd if=/dev/video1 of=snapshot.jpeg bs=11M count=1 which gives me a full size picture using the driver. – reggie Feb 23 '15 at 15:24

1 Answers1

0

You should set the image size before starting to capture, as by default the image is the smallest possible.

Strunz
  • 60
  • 1
  • In the python script or elsewhere? iv tried v4l2-ctl --set-fmt-video=width=2592,height=1944,pixelformat=3 then sudo ./videocaprure_opencv2.py but no joy. – reggie Feb 23 '15 at 17:23
  • You should edit your question and provide a code example. – Steve Robillard Feb 23 '15 at 23:54
  • Hi Steve, I thought I did provided a code example above. I'm not sure how to specify the size in code. – reggie Feb 24 '15 at 14:56
  • http://raspberrypi.stackexchange.com/questions/24262/getting-image-data-from-raspberry-pi-camera-module-in-opencv-with-python has a very similar problem, but I don't seem to be able to use v4l2-ctl to configure the camera module as answer suggests, any ideas, I'm stuck. – reggie Mar 02 '15 at 20:35
  • I placed camera.set(3,800) camera.set(4,600) directly after camera = cv2.VideoCapture(camera_port) and it worked. I wasn't sure from the answer that adding code to the python script was the way to solve it, because the code I quoted in the first comment, was directed at the v4l2-ctl driver. – reggie Mar 03 '15 at 22:19