|
From: kedar m. <ke...@gm...> - 2010-01-16 18:21:57
|
Hi!
I'm trying to write a fairly simple software - a scanner that searches and
decodes any data matrix it finds in an image. I am using opencv functions to
grab frames from the webcam and trying to use libdmtx to check on each frame
for any data matrix present. If any data matrix is found, the software
attempts to decode it.
As of now, I am assuming there is only one data matrix in the image, and on
decoding it, the decoder function returns to main.
However, when I run the code, the code always seems to hang. It appears that
the function call 'msg = dmtxDecodeMatrixRegion(dec, reg, DmtxUndefined);'
is causing the whole program to become unresponsive. If I run the code for
long, it aborts saying "Segmentation Fault".
Is this process extremely slow or processor intensive, which might be
causing the program to behave in this manner?
To compile, I use the options :
> g++ dm.c -ldmtx -o dm pkg-config --cflags --libs opencv
>
The code I am using is a simple combination of some opencv sample and the
libdmtx sample (decoder):
> #ifdef _CH_
> #pragma package <opencv>
> #endif
> #ifndef _EiC
> #include "cv.h"
> #include "highgui.h"
> #include <ctype.h>
> #include <stdio.h>
> #endif
> #ifndef _DM
> #include <stdlib.h>
> #include <stdio.h>
> #include <string.h>
> #include <assert.h>
> #include <dmtx.h>
> #endif
> #include <unistd.h>
> int decode(IplImage* frame);
> int main( int argc, char** argv )
> {
> CvCapture* capture = 0;
> capture = cvCaptureFromAVI( 0 );
> cvNamedWindow( "Data Matrix", 0 );
> int flag=0;
> while(!flag)
> {
> IplImage* frame = 0;
> frame = cvQueryFrame( capture );
> if( !frame )
> break;
> cvShowImage("Data Matrix", frame );
> flag = decode(frame);
> }
> cvReleaseCapture( &capture );
> cvDestroyWindow("Data Matrix");
> return 0;
> }
> int decode(IplImage* frame)
> {
> size_t width=frame->width, height=frame->height,
> bytesPerPixel=frame->nChannels;
> unsigned char *pxl = (unsigned char*) frame->imageData;
> DmtxImage *img;
> DmtxDecode *dec;
> DmtxRegion *reg;
> DmtxMessage *msg;
> int flag=0;
> img = dmtxImageCreate(pxl, width, height, DmtxPack24bppRGB);
> assert(img != NULL);
> dec = dmtxDecodeCreate(img, 1);
> assert(dec != NULL);
> reg = dmtxRegionFindNext(dec, NULL);
> if((reg != NULL) || (!flag))
> {
> msg = dmtxDecodeMatrixRegion(dec, reg, DmtxUndefined);
> if(msg != NULL) {
> fputs("output: ", stdout);
> fwrite(msg->output, sizeof(unsigned char), msg->outputIdx,
> stdout);
> fputs("\n", stdout);
> dmtxMessageDestroy(&msg);
> }
> dmtxRegionDestroy(®);
> flag++;
> }
> dmtxDecodeDestroy(&dec);
> dmtxImageDestroy(&img);
> return flag;
> }
> #ifdef _EiC
> main(1,"dm.c");
> #endif
>
Thanks
Kedar
--
Kedar Prakash Mavinkurve
|