cvGet2D和cvSet2D的目的是什么? [英] Purpose of cvGet2D and cvSet2D?
问题描述
什么是 cvSet2D
和 cvGet2D
实际上做的OpenCV的?就像下面code旋转矩阵,我使用 cvGet2D
:
What are cvSet2D
and cvGet2D
actually doing in OpenCV? Like in the following code to rotate a matrix, I am using cvGet2D
:
CvMat* rot3= cv2DRotationMatrix( center, angle, scale, rot);
cv::Mat rot3cpp(rot3);
for(int j=0;j<rot3cpp.rows;j++)
{
for (int i=0;i<rot3cpp.cols;i++)
{
CvScalar scal = cvGet2D(rot3,j,i);
printf("new matrix is %f: \n", rot3cpp.at<float>(j,i));
}
}
如何使用 cvSet2D
的改变我的code,如果我添加一行:
How will use of cvSet2D
change my code if I add the line:
cvSet2D(rot3,i,j,scal); // set the (i,j) pixel value
在打印前值?
什么是设定(I,J)的像素值呢?
before printing the value? What does "setting (i,j) pixel value" mean?
推荐答案
答案很简单: <$c$c>cvGet2D()$c$c>和<一个href=\"http://docs.opencv.org/modules/core/doc/old_basic_structures.html?highlight=cvset2d#void%20cvSet2D%28CvArr%2a%20arr,%20int%20idx0,%20int%20idx1,%20CvScalar%20value%29\"><$c$c>cvSet2D()$c$c>用于获取并设置一个二维矩阵或图像的元素,分别
Short Answer: cvGet2D()
and cvSet2D()
are used to get and set elements of a two-dimensional matrix or image, respectively.
龙答:
假设你创建一个与CvMat米
:
CvMat* m = cvCreateMat(3, 3, CV_32FC1);
float data[9] = {0, 1, 2, 3, 4, 5, 6, 7, 8};
cvSetData(m, data, m->step);
这将创建一个矩阵看起来像这样:
This creates a matrix which looks like this:
[0.0 1.0 2.0]
[3.0 4.0 5.0]
[6.0 7.0 8.0]
如果你想获得包含值 2.0
,你可以使用元素 cvGet2D()
来获得元件的第一行和第三列中:
If you want to get the element containing the value 2.0
, you would use cvGet2D()
to get the element in the first row and third column:
CvScalar scal = cvGet2D(m, 0, 2); // Rows and columns are zero-indexed
但由于这仅仅是一个单信道矩阵,仅的第一个元素财政
包含有意义的数据。
double value = scal.data[0]; // Voila! value == 2.0
但现在,如果你想改变这种元素的值是什么?那么你可以使用 cvSet2D()
:
CvScalar new_value = cvScalar(9.0);
cvSet2D(m, 0, 2, new_value);
然后,在 M
中的数据是这样的:
[0.0 1.0 9.0] <-- note the change
[3.0 4.0 5.0]
[6.0 7.0 8.0]
这篇关于cvGet2D和cvSet2D的目的是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!