我想在映射後打印出rgbMat的值(在下面的代碼中),但得到一些錯誤。有人可以告訴我我哪裏出錯了嗎?它顯示我以下錯誤:在openCV中訪問rgbMat值
g++ `pkg-config --cflags --libs opencv` line1.cpp
l1.cpp: In function ‘int main(int, char**)’:
l1.cpp:28:50: error: request for member ‘at’ in ‘rgbMat’, which is of non-class type ‘CvMat*’
l1.cpp:28:58: error: expected primary-expression before ‘>’ token
l1.cpp:28:62: error: name lookup of ‘x’ changed for ISO ‘for’ scoping
l1.cpp:28:62: note: (if you use ‘-fpermissive’ G++ will accept your code)
我想我錯了以下行:
printf("matrix is %u: \n", rgbMat.at<uchar>(y,x));
我的代碼是:
IplImage* rgb[3];
float L0[]={
-1,-1,-1,-1,-1,
0, 0, 0, 0, 0,
2, 2, 2, 2, 2,
0, 0, 0, 0, 0,
-1,-1,-1,-1,-1 };
CvMat* rgbMat = cvCreateMat(5, 5, CV_32FC1);
for (int y = 0; y < 5; y++)
{
for (int x = 0; x < 5; x++)
cvmSet(rgbMat, y, x, L0[y*5 + x]);
printf("matrix is %u: \n", rgbMat.at<uchar>(y,x));
}
你正在調用cv :: mat :: at()來自C-api的結構,它不起作用。使用cv :: Mat for C++ api函數。 – hetepeperfan
要從CvMat轉換爲cv :: Mat,構建'cv :: Mat rgbMatcpp(rgbMat)'。然後你可以使用'rgbMatcpp.at(x,y)'。 –
Zaphod
@Zaphod我做了CvMat cv :: Mat轉換,然後pritned爲printf(「matrix is%u:\ n」,rgbMatcpp.at(x,y));但它仍然給我以下錯誤:line1.cpp:在函數'int main(int,char **)'中: l1.cpp:28:63:warning:'x'的名稱查找已更改爲ISO'for'範圍 l1.cpp:26:23:警告:在'x –
user2481422