Good evening, need some help with getting a square area of rgb pixels with openCV Im trying to get the pixels from a 50x50 area on the center of the screen, but i didnt get any success. if i use the output i dont get any pixel else if using original mat(image) its getting the top corner Please someone help
@Override
public void onPreviewFrame(Mat image) {
int w = image.cols();
int h = image.rows();
Mat roi=new Mat(image, new Rect(h/2 , w/2 , 50, 50));
Mat output = roi.clone();
int rw=output.cols();
int rh=output.rows();
//double [] arrp = output.get(rh, rw);//if i use the output i dont get any pixel
double [] arrp = image.get(rh, rw);//if use original mat its getting the top corner
Log.i("",+(int)arrp[2]+" "+ (int)arrp[1]+" "+(int)arrp[0]);
}
I assume you can use copyTo
:
Mat output(50, 50, image.type());
image(Rect(h/2 , w/2 , output.size())).copyTo(output);
The matrix class has an operator (const Rect &roi), that returns a submatrix (without deep data copy). : http://docs.opencv.org/modules/core/doc/basic_structures.html#id6
EDIT:
Didn't see it was for android. I think there is no operator, so you have to use the submat
function :
image.submat(Rect(h/2 , w/2 , output.size())).copyTo(output)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.