russellp has asked for the wisdom of the Perl Monks concerning the following question:
Hi All.
I've looked around quite a bit and can't find a Perl Module that works with Webcam's. So I have decided to write one using OpenCV2.0 and Im having a problem.
My module:
package OpenCV::Webcam; our %EXPORT_TAGS = ( 'all' => [ qw( ) ] ); our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); our @EXPORT = qw( ); our $VERSION = '0.01'; use Inline C => Config => MYEXTLIB => 'C:\OpenCV2.0\lib\libcv200.dll.a C:\OpenCV +2.0\lib\libhighgui200.dll.a C:\OpenCV2.0\lib\libcxcore200.dll.a', INC => '-IC:\OpenCV2.0\include\opencv'; use Inline C => <<'END_OF_C_CODE'; #include "cv.h" #include "highgui.h" CvCapture *capture = 0; IplImage *frame = 0; int* height, width, step, channels, depth; int new() { capture = cvCaptureFromCAM( 0 ); printf("\nSetting Capture!\n"); } char* GetImage() { char *data; printf("\nGetting Image Data!\n"); frame = cvQueryFrame( capture ); cvCvtColor(frame, frame, CV_BGR2RGB); data = (char*)frame->imageData; return(data); } int Release() { printf("\nReleasing Capture!\n"); cvReleaseCapture( &capture ); } END_OF_C_CODE
The problem Im having is in the function GetImage() I return the binary image data back to Perl, their I use Gtk2 to provide a window to display the image.
use Gtk2 '-init'; use Glib qw(TRUE FALSE); use OpenCV::Webcam ; $window = Gtk2::Window->new(); $capture = OpenCV::Webcam::new(); $data = OpenCV::Webcam::GetImage(); $pixbuf = Gtk2::Gdk::Pixbuf->new_from_data ($data, 'rgb', FASLE, 8, 64 +0, 480, 1920); $image = Gtk2::Image->new_from_pixbuf ($pixbuf); $window->add($image); $window->show_all(); Gtk2->main;
The error I get is -
GLib-GObject-CRITICAL **: g_param_spec_float: assertion `default_value + >= minimum && default_value <= maximum' failed at web.pl line 8. Gtk-CRITICAL **: gtk_widget_class_install_style_property: assertion `G +_IS_PARAM_SPEC (pspec)' failed at web.pl line 8.
But sometimes I get an image, But most of the time I get the runtime error.
Im using Perl5.0008 And Gtk2 from lost mind
My question is this: Is the IplImage *frame->imageData from C compatible with Perl? And should it be suitable for Gtk2::Gdk::Pixbuf->new_from_data?
Any help on this is greatly appreciated for it will be FREE software when Im done!
-Thanks,
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Open CV problem
by Tux (Canon) on Dec 09, 2010 at 15:42 UTC | |
by Anonyrnous Monk (Hermit) on Dec 09, 2010 at 16:41 UTC | |
by russellp (Initiate) on Dec 09, 2010 at 17:45 UTC | |
by Anonyrnous Monk (Hermit) on Dec 09, 2010 at 18:25 UTC |