下面是我爲旋轉90度的矩陣(聲明爲rgbMat)代碼,下面訪問元素
CvMat* rot = cvCreateMat(2,3,CV_32FC1);
CvPoint2D32f center = cvPoint2D32f(rgbMat->width/2,rgbMat->height/2);
double angle = 90;
double scale = 5;
CvMat* rot3= cv2DRotationMatrix(center, angle, scale, rot);
更新
我試圖訪問代碼所示rot3的元素,以便我知道我得到的是什麼值。就像下面的代碼: -
cv::Mat rot3cpp(rot3);
for(int i=0;i<rot3cpp.cols;i++)
{
for (int j =0;j<rot3cpp.rows;j++)
{
CvScalar scal = cvGet2D(rot3,i,j);
printf("new matrix is %f: \n", rot3cpp.at<float>(i,j));
}
}
,但我得到的錯誤是這樣的:
OpenCV Error: One of arguments' values is out of range (index is out of range) in cvGet2D, file /home/xyz/Documents/opencv-2.4.5/modules/core/src/array.cpp, line 1958 terminate called after throwing an instance of 'cv::Exception' what(): /home/xyz/Documents/opencv-2.4.5/modules/core/src/array.cpp:1958: error: (-211) index is out of range in function cvGet2D
可有人告訴我,我錯了。任何幫助將不勝感激。
可能重複[如何CvMat中訪問\ *的元素的OpenCV(http://stackoverflow.com/questions/9954423/how-to-access-elements-of-cvmat- in-opencv) – CharlesB
@CharlesB給出的代碼沒有工作,你能提供一些答案 – user2567857
對於打印矩陣,請參考[here](http://docs.opencv.org/doc/tutorials/core/mat%20 - %20the%20basic%20image%20container/mat%20-%20the%20basic%20image%20container.html#print-out-formatting) – devnull