0
이미지 회전을 쓰려고하는데 지금 당장 문제가 있습니다. 내 코드 :OpenCv 어설 션이 ROI에 대해 실패했습니다
Mat rotateMagnify (Mat& img, int degree){
double angle = degree * CV_PI/180.;
double a = sin(angle), b = cos(angle);
int width = img.cols, height = img.rows;
int width_rotate = int(height * fabs(b) - width * fabs(a) + width);
int height_rotate = int(width * fabs(a) + height * fabs(b) + height);
Mat img_rotate;
img_rotate.create((width_rotate, height_rotate), img.depth(), img.channels());
int tempLength = sqrt((double)width * width + (double)height *height) + 10;
int tempX = (tempLength + 1)/2 - width/2;
int tempY = (tempLength + 1)/2 - height/2;
Mat temp;
temp.create((tempLength, tempLength), img.depth(), img.channels());
//cvZero(&img_rotate);
Mat roiImage = temp(Rect(Point(tempX, tempY), Point(width, height)));
//roiImage.ResetImageROI(roiImage);
img.copyTo(roiImage);
float m[6];
int w = roiImage.cols;
int h = roiImage.rows;
m[0] = b;
m[1] = a;
m[3] = -m[1];
m[4] = m[0];
m[2] = w * 0.5f;
m[5] = h * 0.5f;
CvMat M = cvMat(2, 3, CV_32F, m);
cvGetQuadrangleSubPix(&roiImage, &img_rotate, &M);
roiImage.release();
return img_rotate;}
불행히도이 코드는 작동하지 않습니다. 다음과 같은 오류가 발생합니다.
OpenCV Error: Assertion failed (0 <= roi.x && 0 <= roi.width && roi.x +
roi.width <= m.cols && 0 <= roi.y && 0 <= roi.height && roi.y + roi.height
<= m.rows) in cv::Mat::Mat, file C:\builds\master_PackSlave-win32-vc12-
shared\opencv\modules\core\src\matrix.cpp, line 495
이 오류는 어떻게 해결할 수 있습니까? 모두에게 도움을 주셔서 감사합니다!
'width'와'height' 매개 변수를 교환하고 시도해보십시오. –
죄송합니다. 여전히 같은 문제 –
오류를 정확히 내고있는 행은 어느 것입니까? –