안드로이드 폰에서 실시간으로 영상처리 구현 중입니다.

Preview를 가져다가 OpenCV 함수를 적용하려고 하는데

잘 모르겠네요. 인터넷에 떠도는 소스를 참고해서 제가 좀 살을 붙여나가고 있습니다.

몇가지 질문을 요약하면

1. 디버깅 결과 밑에 소스에서 decodeYUV420sp 함수를 호출하고 함수내의

    v = (0xff & yuv420sp[uvp++]) - 128; 부분에서

    "Source not found" 라는 에러가 발생합니다.

 

2. 그리고 opencv.findContours 라는 함수 처리 후 결과를 실시간으로 보여주고 싶은데

    추가적으로 어떻게 구현되어야 하는지 모르겠습니다.

 

3. 중요한 것은 밑의 소스코드도 맞는지 틀린지 모르겠습니다.

    실시간 영상처리 관련 참고자료나 정보 있으시면

    알려주세요 제발..ㅜㅜ 몇주째 진전이 없네요.


---------------------------------소스코드 일부-------------------------------------


 static int v = 0;
 public void surfaceCreated(SurfaceHolder holder) {
  // The Surface has been created, acquire the camera and tell it where
  // to draw.
  camera = Camera.open();
  try {
   camera.setPreviewDisplay(holder);

   camera.setPreviewCallback(new PreviewCallback()
   { 
        public void onPreviewFrame(byte[] _data, Camera _camera) {
              
              // TODO Do something with the preview image.
                //100906_hclee
              
        if(_data == null)
         Log.e(TAG, "onPictureTaken - jpeg is null");
        else
         Log.e(TAG, "onPictureTaken - jpeg is not null");
        
                 int width = _camera.getParameters().getPictureSize().width;
                 int height = _camera.getParameters().getPictureSize().height;                

                 Log.e(TAG, ""+width + " "+height); 
                
                 int []abc = new int[width * height];
       
                
abc = decodeYUV420SP(_data, width, height);
                 OpenCV opencv = new OpenCV();

                 byte[] data = opencv.findContours(abc, width, height);
              
              
              
              contours_Bitmap = BitmapFactory.decodeByteArray(data, 0, data.length);
              
              
              mImageView.setImageBitmap(contours_Bitmap);
              
            
             }
       });


static public int[] decodeYUV420SP(byte[] yuv420sp, int width, int height) {
      final int frameSize = width * height;
      int rgb[] = new int[320*240];
     
      for (int j = 0, yp = 0; j < height; j++) {
        int uvp = frameSize + (j >> 1) * width, u = 0, v = 0;
        for (int i = 0; i < width; i++, yp++) {
         int y = (0xff & ((int) yuv420sp[yp])) - 16;
         if (y < 0) y = 0;
         if ((i & 1) == 0) {
        
 v = (0xff & yuv420sp[uvp++]) - 128;
          u = (0xff & yuv420sp[uvp++]) - 128;
         }
       
        int y1192 = 1192 * y;
        int r = (y1192 + 1634 * v);
        int g = (y1192 - 833 * v - 400 * u);
        int b = (y1192 + 2066 * u);
       
        if (r < 0) r = 0; else if (r > 262143) r = 262143;
        if (g < 0) g = 0; else if (g > 262143) g = 262143;
        if (b < 0) b = 0; else if (b > 262143) b = 262143;
       
        rgb[yp] = 0xff000000 | ((r << 6) & 0xff0000) | ((g >> 2) & 0xff00) | ((b >> 10) & 0xff);
       }
      }
       return rgb;
     }