简体   繁体   English

抛出'cv :: Exception'实例后,OpenCV中出现错误标志错误。 cvGetMat中不支持的数组类型

[英]Bad flag error in OpenCV after throwing an instance of 'cv::Exception' . Unsupported array type in cvGetMat

I am new to OpenCV , and trying to read the sequence of images in a folder. 我是OpenCV的新手,并尝试读取文件夹中的图像序列。 My code is as follows : 我的代码如下:

#include <stdio.h>
#include <opencv2/opencv.hpp>
#include <cv.h>
#include <highgui.h>
#include <iostream>

using namespace cv;
using namespace std;


   void loadImage(Mat image,int number)
    {
      char filename[100];
       strcpy(filename, "/home/folder1/imagefolder/");

     char frameNo[10];
       sprintf(frameNo, "%08i", number); 
       strcat(filename, frameNo);
       strcat(filename, ".png");
       cout<< filename;

       image = imread(filename);
       if (image.empty()) //check whether the image is loaded or not
    {
    cout << "Error : Image not loaded." << endl;
        }
    }

    int main()
    {
     Mat image;
     int nImages=8;
     for (int i = 1; i < nImages; i++)
    {
     loadImage(image,i);
     namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
     imshow( "Display Image", image );
     waitKey(100000);
     return 0;

    }
    }

It gets compiled, But on running the executable, it gives following error: 它被编译,但在运行可执行文件时,它会出现以下错误:

OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat, file /home/vuadmin/OpenCV-2.3.1/modules/core/src/array.cpp, line 2482 terminate called after throwing an instance of 'cv::Exception' what(): /home/vuadmin/OpenCV-2.3.1/modules/core/src/array.cpp:2482: error: (-206) Unrecognized or unsupported array type in function cvGetMat Aborted (core dumped) OpenCV错误:cvGetMat中的错误标志(参数或结构字段)(无法识别或不支持的数组类型),文件/home/vuadmin/OpenCV-2.3.1/modules/core/src/array.cpp,第2482行终止后调用'cv :: Exception'的实例what():/ home / vuadmin / OpenCV-2.3.1 / modules / core / src / array.pp:2482:error:( - 206)函数中的无法识别或不支持的数组类型cvGetMat Aborted (核心倾销)

Please help me find out the error. 请帮我找出错误。

I also tried out the other method as given in OpenCV: Reading image series from a folder 我还尝试了OpenCV中给出的另一种方法:从文件夹中读取图像系列

but in my case it shows only the first image . 但在我的情况下,它只显示第一张图片。

I see several errors in your code : 我在你的代码中看到了几个错误:

your prototype void loadImage(Mat image,int number) makes a copy of the cv::Mat image, so after the call of this function, image is empty. 你的原型void loadImage(Mat image,int number)制作了cv :: Mat图像的副本,所以在调用这个函数之后, image是空的。 You should set the image by reference 您应该通过引用设置图像

void loadImage(Mat& image,int number)

in this case in imshow( "Display Image", image ); 在这种情况下,在imshow( "Display Image", image ); image argument may not be empty. image参数可能不为空。 that may cause your openCV error 这可能会导致您的openCV错误

One other thing in your entry point of your program, you make a return 0; 在你的程序入口点另一件事,你return 0; inside your loop, so the program exit with code value 0 on the first iteration. 在你的循环中,所以程序在第一次迭代时以代码值0退出。 Put the return after the loop. 循环后放回。 Btw, you should "open" your window once, and not on each iteration, but i don't think this causes any error. 顺便说一句,你应该“打开”你的窗口一次,而不是每次迭代,但我不认为这会导致任何错误。

 int main()
    {
     Mat image;
     int nImages=8;
     namedWindow( "Display Image", CV_WINDOW_AUTOSIZE );
     for (int i = 1; i < nImages; i++)
      {
        loadImage(image,i);
        imshow( "Display Image", image );
        waitKey(100000);

      }

     return 0;
    }

You must check the validity of your image after your call of loadImage(image, i) because inside your function, a error message is printed on the standard output, but in your loop, you don't make any check on the image 调用loadImage(image, i)后必须检查图像的有效性,因为在函数内部,标准输出上会显示错误消息,但在循环中,您不会对图像进行任何检查

loadImage(image, i);
if ( ! image.empty ())
    imshow( "Display Image", image );
waitKey(100000);

I had the same error in Java with OpenCV. 我在使用OpenCV的Java中遇到了同样的错误。 I realized that the problem wasn't the images or frames I was using, but the HaarCascade file. 我意识到问题不是我使用的图像或帧,而是HaarCascade文件。 I would try different cascade files (you can find them on OpenCV website), both Haar Cascade files and LBP cascade files. 我会尝试不同的级联文件(你可以在OpenCV网站上找到它们),包括Haar Cascade文件和LBP级联文件。

Hope that helps. 希望有所帮助。 Cheers 干杯

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

相关问题 OpenCV错误:cvGetMat中的错误标志(参数或结构字段)(无法识别或不支持的数组类型) - OpenCV Error: Bad flag (parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat cvGetMat中的错误标志(参数或结构字段)(无法识别或不支持的数组类型) - Bad flag(parameter or structure field) (Unrecognized or unsupported array type) in cvGetMat cvGetMat中无法识别或不支持的数组类型 - Unrecognized or unsupported array type in cvGetMat cvtColor断言失败(带有C ++的OpenCV)抛出实例cv :: exception - cvtColor assertion failed ( OpenCV with C++ ) throwing an instance cv::exception OpenCV错误:错误标志 - OpenCV Error: Bad flag OpenCV错误:cvGetMat中为空指针(传递了NULL数组指针) - OpenCV Error: Null pointer (NULL array pointer is passed) in cvGetMat opencv 3.0中的错误标志错误 - Bad Flag error in opencv 3.0 OpenCV 2.4.2“OpenCV错误:错误标志”出错 - Error in OpenCV 2.4.2 “OpenCV Error: Bad flag” 从线程抛出异常后出现“不良承诺”错误 - “Bad promise” error after throwing an exception from the thread 收到错误“在抛出&#39;std::bad_alloc&#39;what() 的实例后调用终止:std::bad_alloc” - getting error "terminate called after throwing an instance of 'std::bad_alloc' what(): std::bad_alloc"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM