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,


In reply to Open CV problem by russellp

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.