簡體   English   中英

cv :: SimpleBlobDetector detect()在Visual Studio 2010中產生訪問沖突異常

[英]cv::SimpleBlobDetector detect() produce access violation exception in Visual Studio 2010

首先一些背景

我編寫了C ++函數,該函數使用OpenCV在RGB圖像中檢測某種顏色的區域。 該函數用於使用FeatureDetector: SimpleBlobDetector隔離較小的彩色區域。

我的問題是該功能用於跨平台項目中。 在使用Xcode中的OpenCV的OSX 10.8機器上,它可以完美地工作。 但是,當我嘗試在Visual Studio中使用OpenCV在Windows上運行同一段代碼時,無論何時使用,此代碼都會崩潰:

blobDetector.detect(imgThresh, keypoints)

出現這樣的錯誤:

OpenCV Error: Assertion failed (dims <= 2 && data && (unsigned)i0 < (unsigned)size.p[0] && (unsigned)(i1*DataType<_Tp>::channels) < (unsigned)(size.p[1]*channels()) && ((((sizeof(size_t)<<28)|0x8442211) >> ((DataType<_Tp>::depth) & ((1 << 3) - 1))*4) & 15) == elemSize1()) in unknown function, file C:\slave\builds\WinInstallerMegaPack\src\opencv\modules\core\include\opencv2/core/mat.hpp, line 545

到目前為止,這是唯一給我帶來問題的OpenCV代碼。 我嘗試了幾種解決方案,如此處建議的解決方案。 在OpenCV中使用FeatureDetector可以 在FeatureDetector OpenCV 2.4.5中 提供訪問沖突讀取訪問沖突 但無濟於事。

解決我的問題的一種方法是在我對.detect()的調用之前添加一個threshold()調用,這似乎可以使它工作。 但是,我不喜歡這種解決方案,因為它迫使我去做一些我不需要做的事情(據我所知),並且由於某種原因在我的Mac上沒有必要去做。

誰能解釋以下行的原因:

threshold(imgThresh, imgThresh, 100, 255, 0);

在Windows中,但在OSX上不是必需的,僅在以下代碼中對.detect()的調用之前?

完整代碼段:

#include "ColorDetector.h"

using namespace cv;
using namespace std;

Mat ColorDetection(Mat img, Scalar colorMin, Scalar colorMax, double alpha, int beta)
{
    initModule_features2d();
    initModule_nonfree();

    //Define matrices
    Mat contrast_img = constrastImage(img, alpha, beta);
    Mat imgThresh;
    Mat blob;

    //Threshold based on color ranges (Blue/Green/Red scalars)
    inRange(contrast_img, colorMin, colorMax, imgThresh); //BGR range

    //Apply Blur effect to make blobs more coherent
    GaussianBlur(imgThresh, imgThresh, Size(3,3), 0);

    //Set SimpleBlobDetector parameters
    SimpleBlobDetector::Params params;
    params.filterByArea = false;
    params.filterByCircularity = false;
    params.filterByConvexity = false;
    params.filterByInertia = false;
    params.filterByColor = true;
    params.blobColor = 255;
    params.minArea = 100.0f;
    params.maxArea = 500.0f;

    SimpleBlobDetector blobDetector(params);
    blobDetector.create("SimpleBlob");

    //Vector to store keypoints (center points for a blob)
    vector<KeyPoint> keypoints;

    //Try blob detection
    threshold(imgThresh, imgThresh, 100, 255, 0);
    blobDetector.detect(imgThresh, keypoints);

    //Draw resulting keypoints
    drawKeypoints(img, keypoints, blob, CV_RGB(255,255,0), DrawMatchesFlags::DEFAULT);

    return blob;
}

嘗試以這種方式使用它:

Ptr<SimpleBlobDetector> sbd = SimpleBlobDetector::create(params);
vector<cv::KeyPoint> keypoints;
sbd->detect(imgThresh, keypoints);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM