2016-10-19 46 views
0

我使用NI的視覺模塊在LabWindows \ CVI一般保護錯誤使用NI VISION imaqDetectLines()函數

出於某種原因,當我使用FUNC imaqDetectLines(),我得到FATAL RUN-TIME ERROR: "Angle tracker.c", line 50, col 11, thread id 0x00002004: The program has caused a 'General Protection' fault at 0x6C5AD446.

時,這是我的代碼:

#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; 
} 

什麼我實際上做的是:

  1. 打開BMP文件

  2. 邊緣使用SOBEL

  3. 然後我想檢測與imaqDetectLines() FUNC

回答

1

線我發現這個問題imaqEdgeFilter() FUNC filltering它。

,如果你看一下函數調用:

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

對於ROI參數i傳遞NULL,因爲我得到這個從功能面板幫助:

應用於圖像的感興趣區域指定可以檢測到圓圈的位置。將此參數設置爲NULL以搜索整個圖像。

但是,顯然這是一個已知的bug,這將是固定的,所以爲了解決這個,只要做到以下幾點:

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

然後將其發送給函數:

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