简体   繁体   English

opencv 3.0中的错误标志错误

[英]Bad Flag error in opencv 3.0

I am relatively new to opencv and C++ and I would like some help on my code. 我对opencv和C ++相对较新,我想对我的代码有所帮助。 For my project, I am currently working on a simple blob detector but when I run it, I get "OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file C:\\builds\\master_PackSlave-win64-vc12-shared\\opencv\\modules\\core\\src\\array.cpp, line 2494 Press any key to continue . . ." 对于我的项目,我目前正在开发一个简单的Blob检测器,但是运行它时,我在cvGetMat文件C:\\ builds \\ master_PackSlave中收到“ OpenCV错误:错误标志(参数或结构字段)(无法识别或不受支持的数组类型)” -win64-vc12-shared \\ opencv \\ modules \\ core \\ src \\ array.cpp,第2494行按任意键继续。 . I am pretty sure that the error is either from the Mat im_with_keypoints;, or a problem in linker. 我很确定该错误是由于Mat im_with_keypoints;引起的,或者是链接程序中的问题。 Below is my code. 下面是我的代码。 If you could help me that would be great. 如果您能帮助我,那将是很棒的。

  • Update: I ran this program through the debugger and came out with this error 更新:我通过调试器运行该程序,并出现此错误
    • I am also using visual studio 2015 我也在使用Visual Studio 2015

This is the image I am trying to detect for blobs: 这是我要检测的斑点图像:

图片为5个硬币(具体为鹰硬币)

#include "opencv2/highgui/highgui.hpp"  
#include "opencv2/features2d.hpp"
#include "opencv2/opencv.hpp"
#include <opencv2/core/core.hpp>

using namespace cv;
using namespace std;

int main(int argc, char** argv)
{


    Mat im = imread("Eagle_coins.jpg", IMREAD_GRAYSCALE);


    SimpleBlobDetector::Params params;

    params.minThreshold = 10;
    params.maxThreshold = 200;

    params.filterByColor = true;

    params.filterByCircularity = true;
    params.minCircularity = 0.1;
    params.maxCircularity = 0.28;


    params.filterByConvexity = true;
    params.minConvexity = 0.87;
    params.maxConvexity = 2.8;


    params.filterByInertia = true;
    params.minInertiaRatio = 0.01;
    params.maxInertiaRatio = 2;

    vector<KeyPoint> keypoints;

    Ptr<SimpleBlobDetector> detector = SimpleBlobDetector::create(params);

    detector->detect(im, keypoints);

    Mat im_with_keypoints;
    drawKeypoints(im, keypoints, im_with_keypoints, Scalar(0, 0, 255),                       DrawMatchesFlags::DRAW_RICH_KEYPOINTS);

    imshow("white", im_with_keypoints);
    waitKey(0);

}

The minimal code that reproduces the error you mention looks as follows: 产生您提到的错误的最少代码如下所示:

#include <opencv2/opencv.hpp>
#include <opencv2/features2d.hpp>
#include <opencv2/highgui/highgui.hpp>

int main(int argc, char** argv)
{
    cv::Mat im;

    cv::SimpleBlobDetector::Params params;
    std::vector<cv::KeyPoint> keypoints;
    cv::Ptr<cv::SimpleBlobDetector> detector = cv::SimpleBlobDetector::create(params);
    detector->detect(im, keypoints);
}

Console contains 控制台包含

OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file C:\\builds\\master_PackSlave-win64-vc12-shared\\opencv\\modules\\core\\src\\array.cpp, line 2494 OpenCV错误:cvGetMat,文件C:\\ builds \\ master_PackSlave-win64-vc12-shared \\ opencv \\ modules \\ core \\ src \\ array.cpp,第2494行中的错误标志(参数或结构字段)(无法识别或不受支持的数组类型)

and I get a exception from detector->detect with with the message 我从detector->detect异常消息

Unhandled exception at 0x00007FF9A88C7788 in so03.exe: Microsoft C++ exception: cv::Exception at memory location 0x0000005BA676E230. so03.exe中0x00007FF9A88C7788的未处理异常:Microsoft C ++异常:内存位置0x0000005BA676E230的cv :: Exception。

Sidenote: The source of the error would be much more obvious in the debugger, if you had the debug symbols (PDB) available for the library. 旁注:如果您有该库可用的调试符号(PDB),则错误源在调试器中会更加明显。 Unfortunately the package with precompiled binaries distributed from the OpenCV site doesn't contain those, which is why I prefer to build my own. 不幸的是,从OpenCV站点分发的带有预编译二进制文件的软件包不包含那些二进制文件,这就是为什么我更喜欢自己构建二进制文件的原因。

It goes away when we pass a non-empty cv::Mat to detect : 当我们通过一个非空的cv::Matdetect时,它消失了:

#include <opencv2/opencv.hpp>
#include <opencv2/features2d.hpp>
#include <opencv2/highgui/highgui.hpp>

int main(int argc, char** argv)
{
    cv::Mat im(100, 100, CV_8UC3);

    cv::SimpleBlobDetector::Params params;
    std::vector<cv::KeyPoint> keypoints;
    cv::Ptr<cv::SimpleBlobDetector> detector = cv::SimpleBlobDetector::create(params);
    detector->detect(im, keypoints);
}

From this we can conclude, that in your example, imread fails to load the image. 由此我们可以得出结论,在您的示例中, imread无法加载图像。 This is entirely possible, since you don't check for this situation. 这是完全可能的,因为您无需检查这种情况。

Add something like this right after your call to imread : 在致电imread之后, imread添加如下imread

if (im.empty()) {
    std::cerr << "Failed to load image.\n";
    return -1;
}

Now, as to why the image is not loading correctly. 现在,为什么图像不能正确加载。 One option, since you're using Visual Studio, is that you don't have your working directory set up correctly -- by default this is where the project file is located, which is probably not where the exe is. 一种选择,因为您使用的是Visual Studio,所以您没有正确设置工作目录-默认情况下,这是项目文件所在的位置,而exe可能不在此位置。 Either set Debugging > Working Directory appropriately in your project's properties, or use an absolute path to load the image. 在项目的属性中适当地设置“ Debugging > Working Directory ,或使用绝对路径加载映像。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM