2012-01-10 2 views
1

Android 비트 맵에서 1 채널 iplimage (회색)로 변환해야합니다. 나는 가지고있다 :1 채널 iplimage -> Android 비트 맵

IplImage aux = IplImage.create(senal_gray.width, senal_gray.height, IPL_DEPTH_8U, 4); 
cvCvtColor(senal_gray, aux, CV_GRAY2BGRA); 
Bitmap bm = Bitmap.createBitmap(aux.width, aux.height, Bitmap.Config.ARGB_8888); 
bm.copyPixelsFromBuffer(aux.getByteBuffer()); 

이 코드는 반투명 한 그림을 얻기 때문에 문제는 채널 순서에 있다고 생각한다. 아마도 ARGB 순서를 얻고 비트 맵 구성 (ARGB_8888)으로 확인하려면 "aux"에서 채널 순서를 변경해야합니다. 이것이 가능한가?

답변

0

Android 용 OpenCV 바인딩을 사용 해본 적이 없지만 시작하려면 몇 가지 코드가 필요합니다. 의사 코드로 생각해보십시오. 시도 할 수 없기 때문에 ...하지만 기본적인 아이디어를 얻을 수 있습니다.

public static Bitmap IplImageToBitmap(IplImage src) { 
    int width = src.width; 
    int height = src.height; 
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.ARGB_8888); 
    for(int r=0;r<height;r++) { 
     for(int c=0;c<width;c++) { 
      int gray = (int) Math.floor(cvGet2D(src,r,c).getVal(0)); 
      bitmap.setPixel(c, r, Color.argb(255, gray, gray, gray)); 
     } 
    } 
    return bitmap; 
}