Avra Avra - 15 days ago 6
C Question

General Protection error when using NI VISION imaqDetectLines() function

I am using National Instruments Vision module in Labwindows\CVI

For some reason, when i use the func

imaqDetectLines()
, i get
FATAL RUN-TIME ERROR: "Angle tracker.c", line 50, col 11, thread id 0x00002004: The program has caused a 'General Protection' fault at 0x6C5AD446.


This is my code:

#include "nivision.h"
#include <userint.h>
#include <cvirte.h>

int main (int argc, char *argv[])
{
int nLines;
ShapeDetectionOptions stShapeDetectionOption;
RangeFloat aAngleRanges[2]={{0,10.0},{10.0,20.0}};
CurveOptions stCurveOptions = {0};
LineMatch *aLm;
LineDescriptor lineDesc;
Image *imageHdl = NULL, *imageDestHdl = NULL;
char temp[1024] ="";

if (InitCVIRTE (0, argv, 0) == 0)
return -1; /* out of memory */

imageHdl = imaqCreateImage (0/*U8*/,1);
imageDestHdl = imaqCreateImage (0/*U8*/,1);

strcpy(temp,"C:\\CVI2013\\Projects\\Angel Tracker\\IMG\\CC01.bmp");

imaqReadFile (imageHdl, temp, NULL, NULL);

imaqEdgeFilter (imageDestHdl, imageHdl, IMAQ_EDGE_SOBEL, NULL);

lineDesc.maxLength = 100;
lineDesc.minLength = 50;

stShapeDetectionOption.minMatchScore = 1;
stShapeDetectionOption.mode = 0;
stShapeDetectionOption.numAngleRanges = 1;
stShapeDetectionOption.angleRanges = aAngleRanges;
stShapeDetectionOption.scaleRange.minValue = 1;
stShapeDetectionOption.scaleRange.maxValue = 10;

stCurveOptions.extractionMode = 0;
stCurveOptions.threshold = 100;
stCurveOptions.filterSize = 1;
stCurveOptions.minLength = 100;
stCurveOptions.rowStepSize = 10;
stCurveOptions.columnStepSize = 10;
stCurveOptions.maxEndPointGap = 1000;
stCurveOptions.onlyClosed = TRUE;
stCurveOptions.subpixelAccuracy = TRUE;

aLm = imaqDetectLines(imageDestHdl, &lineDesc, &stCurveOptions
,&stShapeDetectionOption, NULL, &nLines);

return 0;
}


what i am actually doing is:


  1. Open a BMP file

  2. Edge filltering it with
    imaqEdgeFilter()
    func using SOBEL

  3. Then i want to detect lines with
    imaqDetectLines()
    func


Answer

I found the problem.

if you look at the function call:

aLm = imaqDetectLines(imageDestHdl, &lineDesc, &stCurveOptions
                       ,&stShapeDetectionOption, NULL, &nLines);   

For the ROI parameter i passed NULL because i got this from The function panel help:

The region of interest applied to the image that specifies where circles can be detected. Set this parameter to NULL to search the entire image.

But, apparently it is a known bug and it will be fixed, so in order to workaround this, just do the following:

ROI *roi;    
imaqSetWindowROI (0, NULL);    
roi = imaqGetWindowROI (0);  

And then send it to the function:

aLm = imaqDetectLines(imageDestHdl, &lineDesc, &stCurveOptions
                       ,&stShapeDetectionOption, roi, &nLines);