Skip to content

Use raspberry pi camera module with OpenCV

mktk1117 edited this page Aug 2, 2016 · 3 revisions

Connect raspberry pi camera module

To know how to connect, please follow this page

Grab a picture and see it from ssh

First, login to the raspberry pi with -X option.

$ ssh -Y raspberry

raspberry is the name set in ~/.ssh/config

The Code

Then, make a python script.

from picamera import PiCamera
from time import sleep

camera = PiCamera()

camera.start_preview(alpha=200)
sleep(5)
camera.capture('image.jpg')
camera.stop_preview()

See with ssh

Run the script. An image file image.jpg should be made. First, install xli

pi@raspberry$ sudo apt-get install xli

Then, see it by doing

xli image.jpg

Publish ROS image(Not worked)

First install required packages

$ sudo apt-get install ros-indigo-image-transport ros-indigo-image-transport-plugins ros-indigo-image-transport-plugins ros-indigo-camera-info-manager

Then, clone the repository, and build it.

$ cd ~/catkin_ws/src
$ git clone https://github.com/fpasteau/raspicam_node.git
$ cd ~/catkin_ws
$ catkin_make

Use OpenCV with raspicam

Since I installed OpenCV 3.1.0, raspicam_cv did not work. So, used raspicam instead.