Page 1 of 1

Simplecv + Camera board guide

Posted: Wed Oct 09, 2013 5:41 pm
by Xfirm
Hello

I have straggled to get the camera board to work with Opencv as I'm an beginner with Linux and the pi. I have got it to work good and I thought I could share it here in case some one else I's straggling with the same thing.

My original goal was to getting it to work with the node-opencv.js module in node but I later found the python simplecv framework. I decide to start with that do there was an good book to start out with. (Practical Computer Vision w. SimpleCV)

I want to do an machine vision system to find parts that should be picked up by an industrial 6-axis robot, another project I want to do is making an home surveillance camera that sends me an mail with an picture if someone is at my door when I'm not home.

I tried some different approach but I found my own way in the end.

So here how I got it to work:

Step 1 - Prepering the SD card
Flashed the SD card with the 2013-09-25-wheezy-raspbian image
http://www.raspberrypi.org/downloads

Step 2 - Installing the camera board on the pi
Install the camera board by following the instruction on this site http://www.raspberrypi.org/camera
Don't forget to activate the camera in the raspi-config

Step 3 - Insatalling simplecv framework
Followed the instruction on the site linked below how to install the simplecv framework
https://github.com/sightmachine/SimpleC ... erryPi.rst

Now the simplecv framework should be installed and you should be able to open the console window by typing

Code: Select all

simplecv 
in the console.

When you are in the simplecv console you should be able to enter following code and there should be an simplecv logo image saved in your user folder. (You need to be in that folder when starting the simplecv console)

Code: Select all

SimpleCV:1> Image("logo").save("Simplecv_logo.jpg")
SimpleCV:1: 1

SimpleCV:2> quit
Write

Code: Select all

quit
and hit enter to close simplecv console. If you then write

Code: Select all

ls
in the console and hit enter. Now there should be an "Simple_logo.jpg" file.

Now you know that simplecv is working

Step4 - Make the pi camera board work as an video device
If you try to axes an camera object you will get the error below:

Code: Select all

SimpleCV:1> cam = Camera()
WARNING: SimpleCV can't seem to find a camera on your system, or the drivers do not work with SimpleCV.

SimpleCV:2>
That because the pi camera board is not an video device. But if you install the UV4L driver following the link below, it will makes an video device like an USB camera would get.
http://www.linux-projects.org/modules/s ... e&artid=14

Start the driver by the following commands:

Code: Select all

[email protected] ~ $ pkill uv4l
[email protected] ~ $ uv4l --driver raspicam --auto-video_nr --encoding yuv420 --nopreview
<notice> [core] Trying driver 'raspicam'
<warning> [core] Driver not found
<notice> [core] Loading external library libraspicam.so
<notice> [core] Trying driver 'raspicam'
<notice> [driver] Raspicam Video4Linux2 Driver v1.7 built Aug 18 2013
<notice> [driver] Selected format: 1920x1088, encoding: yuv420, YUV 4:2:0 Planar (I420), max. 30 fps
<warning> [driver] NOTE: you might need to run the driver with a RealTime scheduling (--sched-rr), if you are going to use the (slow) Read I/O interface at high resolutions.
<notice> [core] Device detected!
<notice> [core] Registering device node /dev/video0
[email protected] ~ $ export LD_PRELOAD=/usr/lib/uv4l/uv4lext/armv6l/libuv4lext.so
[email protected] ~ $
Now the driver should work.
(I'm not sure way you make the export maybe some one can ex plane that and I'm not sure you need to do that eider)

You can check that there are an video device now.

Code: Select all

[email protected] ~ $ ls /dev
autofs           input         mem                 ram11   raw      tty12  tty25  tty38  tty50  tty63      vcs3
block            kmsg          mmcblk0             ram12   rfkill   tty13  tty26  tty39  tty51  tty7       vcs4
btrfs-control    log           mmcblk0p1           ram13   root     tty14  tty27  tty4   tty52  tty8       vcs5
bus              loop0         mmcblk0p2           ram14   shm      tty15  tty28  tty40  tty53  tty9       vcs6
cachefiles       loop1         net                 ram15   snd      tty16  tty29  tty41  tty54  ttyAMA0    vcsa
char             loop2         network_latency     ram2    sndstat  tty17  tty3   tty42  tty55  ttyprintk  vcsa1
console          loop3         network_throughput  ram3    stderr   tty18  tty30  tty43  tty56  uinput     vcsa2
cpu_dma_latency  loop4         null                ram4    stdin    tty19  tty31  tty44  tty57  urandom    vcsa3
cuse             loop5         ppp                 ram5    stdout   tty2   tty32  tty45  tty58  vc-cma     vcsa4
disk             loop6         ptmx                ram6    tty      tty20  tty33  tty46  tty59  vchiq      vcsa5
fb0              loop7         pts                 ram7    tty0     tty21  tty34  tty47  tty6   vc-mem     vcsa6
fd               loop-control  ram0                ram8    tty1     tty22  tty35  tty48  tty60  vcs        [b]video0[/b]
full             MAKEDEV       ram1                ram9    tty10    tty23  tty36  tty49  tty61  vcs1       xconsole
fuse             mapper        ram10               random  tty11    tty24  tty37  tty5   tty62  vcs2       zero
[email protected] ~ $
You can see above that there are an video0 device

Step 5 - Use the camera in simplecv

Start the simplecv console again and test the code below:

Code: Select all

SimpleCV:1> cam = Camera(0, {"width":1280, "height":1024})

SimpleCV:2> cam.getImage().save("test_image.jpg")
SimpleCV:2: 1

SimpleCV:3>
No there should be an image file "test_image.jpg" if you close the simplecv console and look.

Thats it.

References:
http://tothinkornottothink.com/post/593 ... csi-camera
http://www.linux-projects.org/modules/s ... e&artid=14
https://github.com/sightmachine/SimpleC ... erryPi.rst

Please comment if there is something that I missed or you get any problem with this guid.

Re: Simplecv + Camera board guide

Posted: Tue Oct 15, 2013 10:42 pm
by boldbigflank
I tried this out and get a close experience, but there's a couple things.
This is my log:

Code: Select all

SimpleCV:1> cam = Camera(0, {"width":1280, "height":1024})
/dev/video0 does not support memory mapping
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
Unable to stop the stream.: Bad file descriptor
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
munmap: Invalid argument
WARNING: caught exception: SystemError('/dev/video0 does not support streaming i/o',)
WARNING: SimpleCV can't seem to find a camera on your system, or the drivers do not work with SimpleCV.
If I only do

Code: Select all

cam=Camera()
it works, and I get images. Unfortunately, these images are 64x64 resolution. I'd really like to have a useful resolution camera. Any suggestions?

Re: Simplecv + Camera board guide

Posted: Wed Oct 16, 2013 9:07 am
by chihpingkuo
add the following line in your .bashrc file, then open a new shell or reboot

Code: Select all

export LD_PRELOAD=/usr/lib/uv4l/uv4lext/armv6l/libuv4lext.so

Re: Simplecv + Camera board guide

Posted: Wed Oct 16, 2013 9:51 pm
by boldbigflank
That did it! Thank you.

Re: Simplecv + Camera board guide

Posted: Sun Oct 20, 2013 6:07 pm
by benjhoyle
Many thanks for this guide. Very useful.

Unfortunately I am still having a problem with a small image (64x64) in SimpleCV. I have added the LD_PRELOAD variable to .bashrc but this did not solve the problem.

Could you list the sequences of commands you run when starting up SimpleCV?

(I have installed uv4l and it is listing a video0 device.)

Re: Simplecv + Camera board guide

Posted: Mon Oct 21, 2013 8:03 pm
by bvo
benjhoyle wrote:Many thanks for this guide. Very useful.

Unfortunately I am still having a problem with a small image (64x64) in SimpleCV. I have added the LD_PRELOAD variable to .bashrc but this did not solve the problem.

Could you list the sequences of commands you run when starting up SimpleCV?

(I have installed uv4l and it is listing a video0 device.)
Sadly i am facing the same problem, not using simplecv, but python opencv:

Code: Select all

[email protected] ~/test $ uv4l --driver raspicam --auto-video_nr --encoding yuv420 --width 320 --height 240


and in ipython

Code: Select all

In [1]: import cv2
In [2]: cap = cv2.VideoCapture(0)
In [3]: success, img = cap.read()
In [4]: img.shape
Out[4]: (64, 64, 3)
Can someone confirm this?
I am using opencv 2.3 with the latest version of uv4l and uv4l-raspicam

Re: Simplecv + Camera board guide

Posted: Sat Oct 26, 2013 6:32 pm
by RpiName
boldbigflank wrote:Unfortunately, these images are 64x64 resolution. I'd really like to have a useful resolution camera. Any suggestions?
It seems the problem is related to an old version of opencv. Have a look at this post for a solution:

http://www.raspberrypi.org/phpBB3/viewt ... 42#p443742

Re: Simplecv + Camera board guide

Posted: Tue Oct 29, 2013 5:38 pm
by eayars
I'm having a rough time getting SimpleCV and the Raspi CSI camera to play nice, even with uv4l installed, /dev/video0 showing properly, and LD_PRELOAD exported.

SimpleCV will not open a camera: c=Camera() returns the message "WARNING: SimpleCV can't seem to find a camera on your system, or the drivers do not work with SimpleCV."

dd does not work either: dd bs=11M if=/dev/video0 of=test.jpg returns a message about "interrupted system call". I believe this problem MAY be related to my problem with SimpleCV, as on one of the numerous attempts to get SimpleCV working it gave this error before the usual warning.

raspistill works great, so I know the camera is functional: but I really need to use the camera with Python. I'm on Wheezy 2013-09-25, my copy of uv4l is dated 10/24/13, Raspi model B. Any help would be greatly appreciated!

Re: Simplecv + Camera board guide

Posted: Wed Oct 30, 2013 6:48 am
by RpiName
Run rpi-update and retry everything

Re: Simplecv + Camera board guide

Posted: Fri Nov 01, 2013 4:29 am
by eayars
That did it!

Gratzie, Danke, Shei-shei, Gracias, Obrigado, and if you're ever in Northern Northern California let me know: I owe you a beer. :-)

Re: Simplecv + Camera board guide

Posted: Thu Nov 07, 2013 9:40 am
by Alan Johnstone
Is there a way to use this running python in the IDE ?

Re: Simplecv + Camera board guide

Posted: Thu Dec 05, 2013 7:31 am
by KoopCheng
It works!
Thank you very much! Xfirm.

Re: Simplecv + Camera board guide

Posted: Thu Dec 05, 2013 8:34 am
by KoopCheng
I have a question:

In SimpleCV interactive shell, I can use the Camera object to get pictures from PiCam. However, when I use the Camera object in Python Shell (IDLE), the system says that "AttributeError: Camera instance has no attribute 'threaded'.

Could anyone help me to solve the problem?
Thank you.

== Message on the Console ==
WARNING: SimpleCV can't seem to find a camera on your system, or the drivers do not work with SimpleCV.

Traceback (most recent call last):
File "/home/pi/Desktop/MyProject/HelloFaceRecognition_SCV/faceRec.py", line 8, in <module>
frame = myCamera.getImage()
File "/usr/local/lib/python2.7/dist-packages/SimpleCV/Camera.py", line 579, in getImage
if (not self.threaded):
AttributeError: Camera instance has no attribute 'threaded'

Re: Simplecv + Camera board guide

Posted: Thu Dec 05, 2013 10:59 am
by KoopCheng
I use "myCamera = Camera(0)" with no additional parameters to initiate the Camera object,
and it can get images from the PiCam without the 'AttributeError'.

But the image resolution is low (64px x 64px)
KoopCheng wrote:I have a question:

In SimpleCV interactive shell, I can use the Camera object to get pictures from PiCam. However, when I use the Camera object in Python Shell (IDLE), the system says that "AttributeError: Camera instance has no attribute 'threaded'.

Could anyone help me to solve the problem?
Thank you.

== Message on the Console ==
WARNING: SimpleCV can't seem to find a camera on your system, or the drivers do not work with SimpleCV.

Traceback (most recent call last):
File "/home/pi/Desktop/MyProject/HelloFaceRecognition_SCV/faceRec.py", line 8, in <module>
frame = myCamera.getImage()
File "/usr/local/lib/python2.7/dist-packages/SimpleCV/Camera.py", line 579, in getImage
if (not self.threaded):
AttributeError: Camera instance has no attribute 'threaded'

Re: Simplecv + Camera board guide

Posted: Wed Feb 12, 2014 8:04 pm
by Mike1342
:roll: Hi, I am new and I am trying to use a SCI camera with simpleCV. After Iinstalling UV4L driver and simpleCv, I run cam=Camera() and both my mouse and keyboard stop working. Could anybody help me with this problem. Thanks

Re: Simplecv + Camera board guide

Posted: Tue Mar 11, 2014 4:19 pm
by hkn
I've gotten the driver to work with the picam and I'm running tests using both pygame and SimpleCV and for both cases whenever I start up the camera there's a preview of the camera output covering the display from either SimpleCV or pygame.

Is it possible to prevent this camera preview to be ontop or just to hide it?

Re: Simplecv + Camera board guide

Posted: Sat Mar 29, 2014 9:40 pm
by TheLowEndTheory
I too have this problem where the image preview covers the whole page, and the 64x64 issue, will installing a newer version of openCV work even though I am exclusively using simpelCV?

Re: Simplecv + Camera board guide

Posted: Thu Apr 03, 2014 11:59 pm
by SunDreammer
TheLowEndTheory wrote:I too have this problem where the image preview covers the whole page, and the 64x64 issue, will installing a newer version of openCV work even though I am exclusively using simpelCV?
Hey, like the username. I'm a big quest fan. Ok here is what you need to do. I just got my install working after 3 frustrating days. Go to this link and follow the instructions for a fresh install of the current version of opencv. http://robertcastle.com/2014/02/install ... pberry-pi/
After that do these steps as well so you can fully configure opencv and make certain that it works:
CONFIGURE OPENCV
In your terminal, execute:

sudo nano /etc/ld.so.conf.d/opencv.conf

Add the following line and save it:

/usr/local/lib

Now, in your terminal, execute:

sudo ldconfig

Again, execute:

sudo nano /etc/bash.bashrc

Add the following two lines at the end of the file and save it:

PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig
export PKG_CONFIG_PATH

Finally, reboot your computer.

TRY AN EXAMPLE

To test an example, from your terminal cd to the OpenCV folder. Once you're inside it cd to samples/c.

Now, execute:

chmod +x build_all.sh

./build_all.sh

./facedetect lena.jpg

ok opencv works you're ready for simplecv ( although if you can't get simplecv there are some good youtube vids and books for opencv )

I did this: $ sudo apt-get install ipython python-opencv python-scipy python-numpy python-setuptools python-pip python-pygame



sudo apt-get install git
git clone git://github.com/sightmachine/SimpleCV.git
cd SimpleCV
sudo pip install -r requirements.txt
python setup.py install
sudo python setup.py develop


after that go here:

http://www.linux-projects.org/modules/s ... e&artid=14

after that it's the same as the steps on this page ( start the uv4l driver and then enter the simplecv console) if it doesn't work, remember to edit the bash file and to do the updates and reboot. I will check back to see if there are any questions.

Re: Simplecv + Camera board guide

Posted: Thu Apr 10, 2014 12:55 pm
by kkannan
As many posts pointed out, I am having the same issue of 64x64. I tried downloading and building opencv as instructed, but it failed at various stages.

Could someone please make the working SD image with all packages installed available for download ? It'll be a great favour since not everyone can successfully rebuild OpenCV.

Thanks

Re: Simplecv + Camera board guide

Posted: Wed Nov 05, 2014 8:23 pm
by msadeghy
hi
Im using Camera() for initialize raspberry camera in simpleCV.
when I use cam=Camera() a window opens & I have no control on it.
before first shutting down after simpleCV installing I dont had this problem.
help me for dont showing this window
excuse me for poor english.

Re: Simplecv + Camera board guide

Posted: Tue Nov 11, 2014 9:25 pm
by neverbend007
Hi, I am having the same issue here with 64px by 64px resolution. I have both openCV and simpCV installed on my Pi. openCV works fine and I am able to change the res as I see fit but simpleCV wont change the res no matter what I do. I've tried changing the conf file but still the same.

Re: Simplecv + Camera board guide

Posted: Tue Mar 03, 2015 3:11 pm
by neverbend007
For anyone still struggling with this, I found a work around, pass the image from picamera to openCV as a stream, see this article: http://picamera.readthedocs.org/en/latest/recipes1.html

Re: Simplecv + Camera board guide

Posted: Wed Jun 14, 2017 8:18 am
by trevery

Re: Simplecv + Camera board guide

Posted: Wed Jun 06, 2018 2:36 pm
by alic_belmin
Hi guys,

I hope someone is still on this topic, since I desperately need help.

I am trying to make a barcode scanner with a Raspi Pi 3 and a Raspi V2.1 NOIR Camera.

I followed all the steps from this tutorial and was able to install SimpleCV and to run it. (Have also done the test with the SimpleCV logo.) The camera is functioning as well.
I have also reserved 512 MB of RAM for the GPU.

However, when trying to initialize an instance of object Camera(), I get the following error:

Code: Select all

SimpleCV:1> cam = Camera()
/bin/sh: 1: lsof: not found
Fatal Python error: (pygame parachute) Segmentation Fault
Aborted
I have noticed some warning messages when inizializing SimpleCV, so I will copy that as well:

Code: Select all

/home/pi/.local/lib/python2.7/site-packages/IPython/config.py:13: ShimWarning: The `IPython.config` package has been deprecated. You should import from traitlets.config instead.
  "You should import from traitlets.config instead.", ShimWarning)
/home/pi/.local/lib/python2.7/site-packages/IPython/frontend.py:21: ShimWarning: The top-level `frontend` package has been
deprecated. All its subpackages have been moved to the top `IPython` level.
  "All its subpackages have been moved to the top `IPython` level.", ShimWarning)
+-----------------------------------------------------------+
 SimpleCV 1.3.0 [interactive shell] - http://simplecv.org
+-----------------------------------------------------------+

Commands:
        "exit()" or press "Ctrl+ D" to exit the shell
        "clear()" to clear the shell screen
        "tutorial()" to begin the SimpleCV interactive tutorial
        "example()" gives a list of examples you can run
        "forums()" will launch a web browser for the help forums
        "walkthrough()" will launch a web browser with a walkthrough

Usage:
        dot complete works to show library
        for example: Image().save("/tmp/test.jpg") will dot complete
        just by touching TAB after typing Image().

Documentation:
        help(Image), ?Image, Image?, or Image()? all do the same
        "docs()" will launch webbrowser showing documentation

SimpleCV:1> cam = Camera()
/bin/sh: 1: lsof: not found
Fatal Python error: (pygame parachute) Segmentation Fault
Aborted
I am running the latest Raspbian Stretch Lite and have already updated it several times.



Any kind of help would be more than appretiated.

Thank you in advance,
Belmin.

Re: Simplecv + Camera board guide

Posted: Thu Nov 15, 2018 6:49 pm
by JosueGO
alic_belmin wrote:
Wed Jun 06, 2018 2:36 pm
Hi guys,

I hope someone is still on this topic, since I desperately need help.

I am trying to make a barcode scanner with a Raspi Pi 3 and a Raspi V2.1 NOIR Camera.

I followed all the steps from this tutorial and was able to install SimpleCV and to run it. (Have also done the test with the SimpleCV logo.) The camera is functioning as well.
I have also reserved 512 MB of RAM for the GPU.

However, when trying to initialize an instance of object Camera(), I get the following error:

Code: Select all

SimpleCV:1> cam = Camera()
/bin/sh: 1: lsof: not found
Fatal Python error: (pygame parachute) Segmentation Fault
Aborted
I have noticed some warning messages when inizializing SimpleCV, so I will copy that as well:

Code: Select all

/home/pi/.local/lib/python2.7/site-packages/IPython/config.py:13: ShimWarning: The `IPython.config` package has been deprecated. You should import from traitlets.config instead.
  "You should import from traitlets.config instead.", ShimWarning)
/home/pi/.local/lib/python2.7/site-packages/IPython/frontend.py:21: ShimWarning: The top-level `frontend` package has been
deprecated. All its subpackages have been moved to the top `IPython` level.
  "All its subpackages have been moved to the top `IPython` level.", ShimWarning)
+-----------------------------------------------------------+
 SimpleCV 1.3.0 [interactive shell] - http://simplecv.org
+-----------------------------------------------------------+

Commands:
        "exit()" or press "Ctrl+ D" to exit the shell
        "clear()" to clear the shell screen
        "tutorial()" to begin the SimpleCV interactive tutorial
        "example()" gives a list of examples you can run
        "forums()" will launch a web browser for the help forums
        "walkthrough()" will launch a web browser with a walkthrough

Usage:
        dot complete works to show library
        for example: Image().save("/tmp/test.jpg") will dot complete
        just by touching TAB after typing Image().

Documentation:
        help(Image), ?Image, Image?, or Image()? all do the same
        "docs()" will launch webbrowser showing documentation

SimpleCV:1> cam = Camera()
/bin/sh: 1: lsof: not found
Fatal Python error: (pygame parachute) Segmentation Fault
Aborted
I am running the latest Raspbian Stretch Lite and have already updated it several times.



Any kind of help would be more than appretiated.

Thank you in advance,
Belmin.
HI, you could solve that error?

I try to do the same thing and he gave me that same error

Thank you in advance