2013-12-17 4 views
0

안녕하세요, openCV로 rgb 픽셀의 정사각형 영역을 얻는 데 도움이 필요합니다 저는 화면 중앙의 50x50 영역에서 픽셀을 얻으려고하고 있지만 성공하지 못했습니다. 내가 출력을 사용하면 원래 매트 (이미지)의 상단 를 얻기를 사용하는 사람이안드로이드 OpenCV 만들기 레프트

@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]); 
} 

답변

3

도와주세요 경우 은 내가 당신이 사용할 수있는 가정 다른 모든 픽셀을 얻을 그나마 copyTo :

Mat output(50, 50, image.type()); 
image(Rect(h/2 , w/2 , output.size())).copyTo(output); 

matrix 클래스에는 하위 데이터 복사본이없는 연산자 (const Rect & roi)가 있습니다. : http://docs.opencv.org/modules/core/doc/basic_structures.html#id6

편집 :

이 안드로이드를위한이었다 보지 않았다. 제 생각에는 연산자가 없으므로 submat 함수를 사용해야합니다.

image.submat(Rect(h/2 , w/2 , output.size())).copyTo(output)