简体   繁体   中英

Assertion failed ROI opencv

I use visual studio 2012 with opencv 3.0. I already checked several post about this issue but still I get assertion failed error -215 when I run this code:

 IplImage * imageOriginal = cvLoadImage("road1.jpg"); int width = 0, height = 0; width = imageOriginal->width; height = imageOriginal->height; IplImage* img = cvCreateImage(cvGetSize(imageOriginal), imageOriginal->depth , 3); CvRect cropRect = cvRect(0, 0, width -10, height -10 ); // ROI in source image cvSetImageROI(imageOriginal, cropRect); try { cvCopy(imageOriginal, img, NULL); // Copies only crop region } catch (cv::Exception& e) { cout << e.what() << endl; } cvResetImageROI(imageOriginal); cvShowImage( "Original ROI", img); waitKey(); 

If I leave the rectangle to be full size CvRect cropRect = cvRect(0, 0, width, height); I get no error. What is the problem?

your code is from opencv1.0. (that was a long time ago)

please, for opencv3.0, use the c++ api instead:

#include <opencv2/core.hpp>
#include <opencv2/imgcodecs.hpp>
#include <opencv2/highgui.hpp>
using namespace cv;

int main() {
    Mat img = imread("road1.jpg");
    Mat roi = img(Rect(0,0,img.cols-10,img.rows-10));
    imshow("hi",roi);
    return waitKey();
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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