Ask Your Question
0

problem in cvtColor function

asked 2013-03-25 05:35:07 -0600

pocahentez gravatar image

updated 2020-10-05 08:34:01 -0600

Hi,I have a native methode which play frame so i retreive the pixels of the image into a byte [] buffer and call a java methode to proceed the processing :

 public void processCameraImage(byte[] buffer, int width, int height)  {
    System.out.println("setRGB565CameraImage....intent received..."); 
    Bitmap bitmap = Bitmap.createBitmap(width, height, Bitmap.Config.RGB_565);
    Mat inputFrame= new Mat();
    inputFrame.put(0, 0, buffer);
    if(inputFrame.channels()==1)
    {      /* Grayscale */  Log.i("grayscale", "grayscale"); 
   Imgproc.cvtColor(inputFrame, mGray, Imgproc.COLOR_GRAY2BGR565); // i have a problem here//
    }
    else if (inputFrame.channels()==4)
    {      /* ARGB or RGBA image */      Log.i("ARGB or RGBA", "ARGB or RGBA");                               }
    else
    {      /* RGB, BGR, HSV, or any other 3-channel representation */Log.i("RGB, BGR, HSV", "RGB, BGR, HSV");   }
  //ect
   }

i have this in logcat:

03-24 11:23:45.322: I/System.out(9915): setRGB565CameraImage....intent received...
03-24 11:23:45.362: D/dalvikvm(9915): GC_CONCURRENT freed <1K, 22% free 8108K/10311K, paused 1ms+3ms   
03-24 11:23:45.372: I/grayscale(9915): grayscale    
03-24 11:23:45.372: W/dalvikvm(9915): JNI WARNING: JNI method called with exception pending

03-24 11:23:45.372: W/dalvikvm(9915):  in Lcom/qualcomm/ar/pl/CameraPreview;.newFrameAvailable:       (IIII[B)V (CallIntMethodV)
03-24 11:23:45.372: W/dalvikvm(9915): Pending exception is:
03-24 11:23:45.372: I/dalvikvm(9915): java.lang.NullPointerException:
03-24 11:23:45.372: I/dalvikvm(9915):   at   org.opencv.imgproc.Imgproc.cvtColor(Imgproc.java:4354)
03-24 11:23:45.372: I/dalvikvm(9915): at   com.qualcomm.QCARSamples.ImageTargets.ImageTargets.processCameraImage(ImageTargets.java:524)
03-24 11:23:45.372: I/dalvikvm(9915): at com.qualcomm.ar.pl.CameraPreview.newFrameAvailable(Native Method)

Please i need help as soon as possible i'm stucked here.

edit retag flag offensive close merge delete

Comments

also what does this: Imgproc.cvtColor(mRgba, mGray, Imgproc.COLOR_BGRA2GRAY); in t he face detection sample?does it mean that we convert mrgba matrix into 1 chanel and stored in mgray matrix?

pocahentez gravatar imagepocahentez ( 2013-03-25 05:53:03 -0600 )edit

2 answers

Sort by ยป oldest newest most voted
1

answered 2013-03-25 07:17:35 -0600

Exception means than inputFrame or mGray objects are null.

edit flag offensive delete link more
2

answered 2013-03-25 10:42:46 -0600

Andrey Pavlenko gravatar image

Actually when you create a Mat via

Mat inputFrame= new Mat();

it's created empty, i.e. contains zero elements/pixels; then the call to

inputFrame.put(0, 0, buffer);

does nothing since there is no destination memory. You need to allocate the Mat, e.g if you're sure that buffer contains RGB565 pixels:

Mat inputFrame= new Mat(height, width, CvType.CV_8UC2);
edit flag offensive delete link more

Comments

thank you it is clear now.

pocahentez gravatar imagepocahentez ( 2013-03-26 03:09:55 -0600 )edit

Question Tools

Stats

Asked: 2013-03-25 05:35:07 -0600

Seen: 2,509 times

Last updated: Mar 26 '13