Difference between revisions of "OpenCV"

From ElphelWiki
Jump to: navigation, search
(Using AVLD)
(Using v4lsink GStreamer plugin and v4l2loopback)
 
(5 intermediate revisions by one other user not shown)
Line 10: Line 10:
 
While it is the only solution with proprietary v4l compatible software products (such as skype), it's a total waste of resources for a free software app what can be adapted to receive an RTP stream.
 
While it is the only solution with proprietary v4l compatible software products (such as skype), it's a total waste of resources for a free software app what can be adapted to receive an RTP stream.
  
Moreover, you can downloa from:
+
Moreover, you can proceed to download the source code from:
 
   http://allonlinux.free.fr/Projets/AVLD/src/avld_0.1.4.tar.bz2
 
   http://allonlinux.free.fr/Projets/AVLD/src/avld_0.1.4.tar.bz2
  
Line 33: Line 33:
 
   int main(int argc,char *argv[])
 
   int main(int argc,char *argv[])
 
   {
 
   {
 +
    cvNamedWindow( "Current Frame");
 
     IplImage* pCurrentFrame = NULL;
 
     IplImage* pCurrentFrame = NULL;
 
     CvSize frame_size;
 
     CvSize frame_size;
Line 40: Line 41:
 
       {
 
       {
 
         //Request frame from Camera
 
         //Request frame from Camera
pCurrentFrame = cvQueryFrame ( capture );
+
        pCurrentFrame = cvQueryFrame ( capture );
//video input file finished
+
        //video input file finished
if( !pCurrentFrame ) break;
+
        if( !pCurrentFrame ) break;
 
         cvShowImage( "Current Frame", pCurrentFrame );
 
         cvShowImage( "Current Frame", pCurrentFrame );
 
         c = cvWaitKey(10);
 
         c = cvWaitKey(10);
Line 51: Line 52:
 
     return 0;
 
     return 0;
 
   }
 
   }
 +
 +
--[[User:maurosc3ner|Esteban Correa]] 21:54, 29 July 2010 (CDT)
  
 
==Using v4lsink GStreamer plugin and v4l2loopback==
 
==Using v4lsink GStreamer plugin and v4l2loopback==
 
This is basically an AVLD fork that now evolved into v4l2loopback and a special gstreamer sink to the loopback device.
 
This is basically an AVLD fork that now evolved into v4l2loopback and a special gstreamer sink to the loopback device.
  
http://code.google.com/p/v4lsink/ & http://code.google.com/p/v4l2loopback/
+
You can find the projects homepages at: http://code.google.com/p/v4lsink/ & http://code.google.com/p/v4l2loopback/ (This version does not compile due to vala dependencies, somebody cloned and patched the project, it is available from github: http://github.com/umlaeute/gst-v4l2loopback)
 +
 
 +
To install it do:
 +
hg clone https://v4l2loopback.googlecode.com/hg/ v4l2loopback 
 +
cd v4l2loopback
 +
make
 +
make install
 +
 
 +
load the module:
 +
modprobe v4l2loopback
 +
 
 +
To compile v4lsink you will need Vala compiler >= 0.8.1, the easy way is to install the package from Vala PPA:
 +
sudo add-apt-repository ppa:vala-team/ppa
 +
sudo apt-get update
 +
sudo apt-get install valac vala-utils
 +
It will install valac 0.9.1 instead of default 0.8.0 under Ubuntu 10.04.
 +
 
 +
Install v4lsink:
 +
git clone http://github.com/umlaeute/gst-v4l2loopback.git
 +
cd gst-v4l2loopback
 +
./autogen.sh
 +
make
 +
make install
 +
This will install the new gstreamer module in ~/.gstreamer-0.10/plugins/ folder. Now you can try "gst-inspect v4l2loopback"
 +
 
 +
Default resolution is fixed to 640x480, if you want to change the resolution, you can change it in the two places of the v4l2loopback.c file and recompile/reinstall v4lsink.
 +
 
 +
To test it with an RTSP stream from an Elphel camera you need to feed the stream into the loopback device:
 +
gst-launch -e -m rtspsrc location=rtsp://192.168.0.9:554 latency=50 ! rtpjpegdepay ! jpegdec ! ffmpegcolorspace ! v4l2loopback
 +
 
 +
Now you can open the stream as v4l2 device with any compatible program:
 +
mplayer tv:// -tv device=/dev/video1
 +
 
 +
To test with OpenCV simply change the v4l2 device number:
 +
// CvCapture* capture = 0;
 +
    CvCapture* capture = 1;
  
 
==Using OpenCV with FFMPEG==
 
==Using OpenCV with FFMPEG==

Latest revision as of 07:31, 29 August 2010

Single image

You can use imgsrv to download a single image from the circbuf. MJPEG live stream is also available from imgsrv.

You can use wget to download the image to your computer or implement a small HTTP client in your software.

Live video

Using AVLD

AVLD stand for AVLD - Another Video Loopback Device. It's a very CPU and RAM consuming way to present an Elphel network camera as V4l device.

While it is the only solution with proprietary v4l compatible software products (such as skype), it's a total waste of resources for a free software app what can be adapted to receive an RTP stream.

Moreover, you can proceed to download the source code from:

 http://allonlinux.free.fr/Projets/AVLD/src/avld_0.1.4.tar.bz2

Then:

 $ tar -jxvf avld_0.1.4.tar.bz2
 $ cd avld_0.1.4
 $ make && sudo make install

Right now you can mount your dummy device typing:

 $sudo modprobe avld width=<camera width resolution> height=<camera height resolution> fps=<camera fps>

Finally, you need to use mencoder in order to redirect the rtsp source to the dummy device:

 $ sudo mencoder rtsp://192.168.1.180 -nosound -ovc raw -vf format=bgr24 -of rawvideo -o /dev/video0

With this, you just need a simple code in order to preview the scene:

 #include "highgui.h"
 #include "cv.h"
 #include "cvaux.h"
 #include <ml.h>
 
 int main(int argc,char *argv[])
 {
   cvNamedWindow( "Current Frame");
   IplImage* pCurrentFrame = NULL;
   CvSize frame_size;
   CvCapture* capture = cvCaptureFromCAM ( 0 ); //the dummy device make the job :)
   char c;
   while ( 1 )
     {
       //Request frame from Camera
       pCurrentFrame = cvQueryFrame ( capture );
       //video input file finished		
       if( !pCurrentFrame ) break;
       cvShowImage( "Current Frame", pCurrentFrame );
       c = cvWaitKey(10);
       if ( c == 27 ) break;
     }
   cvReleaseImage ( &pCurrentFrame );
   cvDestroyAllWindows ();
   return 0;
 }

--Esteban Correa 21:54, 29 July 2010 (CDT)

Using v4lsink GStreamer plugin and v4l2loopback

This is basically an AVLD fork that now evolved into v4l2loopback and a special gstreamer sink to the loopback device.

You can find the projects homepages at: http://code.google.com/p/v4lsink/http://code.google.com/p/v4l2loopback/ (This version does not compile due to vala dependencies, somebody cloned and patched the project, it is available from github: http://github.com/umlaeute/gst-v4l2loopback)

To install it do:

hg clone https://v4l2loopback.googlecode.com/hg/ v4l2loopback  
cd v4l2loopback
make
make install

load the module:

modprobe v4l2loopback

To compile v4lsink you will need Vala compiler >= 0.8.1, the easy way is to install the package from Vala PPA:

sudo add-apt-repository ppa:vala-team/ppa
sudo apt-get update
sudo apt-get install valac vala-utils

It will install valac 0.9.1 instead of default 0.8.0 under Ubuntu 10.04.

Install v4lsink:

git clone http://github.com/umlaeute/gst-v4l2loopback.git
cd gst-v4l2loopback
./autogen.sh
make
make install

This will install the new gstreamer module in ~/.gstreamer-0.10/plugins/ folder. Now you can try "gst-inspect v4l2loopback"

Default resolution is fixed to 640x480, if you want to change the resolution, you can change it in the two places of the v4l2loopback.c file and recompile/reinstall v4lsink.

To test it with an RTSP stream from an Elphel camera you need to feed the stream into the loopback device:

gst-launch -e -m rtspsrc location=rtsp://192.168.0.9:554 latency=50 ! rtpjpegdepay ! jpegdec ! ffmpegcolorspace ! v4l2loopback

Now you can open the stream as v4l2 device with any compatible program:

mplayer tv:// -tv device=/dev/video1

To test with OpenCV simply change the v4l2 device number:

// CvCapture* capture = 0;
   CvCapture* capture = 1;

Using OpenCV with FFMPEG

Using OpenCV with GStreamer

Design your OpenCV code as GStreamer plugin

http://github.com/Elleo/gst-opencv

Portability

Tutorials

Tennis balls recognizing

OpenCV Tennis balls recognizing tutorial

Go game record (kifu) generator

Kifu:_Go_game_record_(kifu)_generator