在学习opencv的书中,第3章有一个问题:
Create a two dimensional matrix with three channels of type byte with data size 100-by-100 and initialize all the values to 0.
Use the pointer element to access cvptr2D to point to the middle 'green' channel.Draw the rectangle between 20,5 and 40,20.
我已经设法完成了第一部分,但我无法理解第二部分。这是我到目前为止所做的:
/*
Create a two dimensional matrix with three channels of type byte with data size 100- by-100 and initialize all the values to 0.
Use the pointer element to access cvptr2D to point to the middle 'green' channel.Draw `enter code here`the rectangle between 20,5 and 40,20.
*/
void ex10_question3(){
CvMat* m = cvCreateMat(100,100,CV_8UC3);
CvSetZero(m); // initialize to 0.
uchar* ptr = cvPtr2D(m,0,1); // if RGB, then start from first RGB pair, Green.
cvAdd(m,r);
cvRect r(20,5,20,15);
//cvptr2d returns a pointer to a particular row element.
}
我正在考虑同时添加矩形和矩阵,但显然这不起作用,因为矩形只是坐标和宽度/高度。我不熟悉 cvPtr2D()。我怎样才能想象练习要我做什么,谁能给我一个正确方向的提示?解决方案必须在 C 中。
根据我对交错 RGB 通道的理解,第二个通道将始终是感兴趣的通道。(数组索引:1,4,6..)