이미지의 높이와 너비를 반으로 잘라서 잘라내려고하면 원래 이미지의 절반을 사용하려고합니다. 아래의 [1]opencv에서 선택된 픽셀로 이미지 자르기
내 코드이다 [화상 잘려서] 그러나 런타임 예외 .exe 파일을 일으키는 이하 오류 작동하지 :
OpenCV Error: Assertion failed (rect.width >= 0 && rect.height >= 0 && rect.x < image->width && rect.y < image->height && rect.x + rect.width >= (int)(rect.width > 0) && rect.y + rect.height >= (int)(rect.height > 0)) in cvSetImageROI, file C:\Development\opencv\sources\modules\core\src\array.cpp, line 3006
This application has requested the Runtime to terminate it in an unusual way.
Please contact the application's support team for more information.
이하이고 코드 :
#include <iostream>
#include <string>
#include <opencv/cv.h>
#include <opencv/cxcore.h>
#include <opencv/highgui.h>
using namespace std;
using namespace cv;
int main(int argc, char** argv) {
IplImage *img1 = cvLoadImage("image/testcase.jpg");
cvNamedWindow("Image1:",1);
cvShowImage("Image1:",img1);
cout << "Width:" << img1->width <<" pixels"<< endl;
cout << "Height:" << img1->height <<" pixels"<< endl;
int width = img1->width ;
int lenght = img1->height;
// cropping the image
Rect roi;
roi.x = width;
roi.y = lenght;
roi.width = (roi.x)/2;
roi.height = (roi.y)/2;
Mat image_test;
image_test = imread("image/testcase");
// Must have dimensions of output image
IplImage* cropped = cvCreateImage(cvSize(roi.width,roi.height), img1->depth, img1->nChannels);
cvSetImageROI(img1, roi);
cvCopy(img1, cropped);
cvResetImageROI(img1);
cvNamedWindow("Cropped Image", 1);
cvShowImage("Cropped Image", cropped);
cvSaveImage ("savedImage/cropped.jpg" , cropped);
waitKey(0);
return 0;
}
사용하고있는 모든 특별한 이유 ** 쓸모 * * C api? – Miki