c++ - Android convert byte array from Camera API to color Mat object openCV -


I stopped the camera API and am trying to process color post. My problem is that when I can convert a byte [] object to a muted object, I can not get a color channel without getting any errors I started with the following post: but this implementation does not work .

Here is the relevant code:

  @Override Illustration on public vignettes (byte [] data, camera camera) {// Camera preview was automatically shut down. Start it again mCamera.startPreview (); MCamera.setPreviewCallback (this); // file in a file (in jpeg format) file image file_interp = getOutputMediaFile (MEDIA_TYPE_IMAGE); try {// now try to convert and save parameter parameter = camera.getParameters (); Size sz = params.getPictureSize (); // error in the bottom line !!!! Mat raw = new mat (sz.height, sz.width, cvType.CV_8UC4); Raw.put (0, 0, data); Mat targ = highigiimd code (raw, 0); Orig = new mat (); Imgproc.cvtColor (targ, orig, Imgproc.COLOR_GRAY2RGB); //Iggproc.cvtColor (Targ, Fixed, Improp. COLOR_BGR2RGB); // Now we have the goal that we want ... let's repeat. Interp = interpExperiment (orig, interpBy); Haigui.Emirit (picturefile_interp.ststring (), interpic); } Finally {}}   

When I try that code, I get an exception:

  Data element provided is mat channel Counting should be several (3)   

Instead of

  Mat raw = new Mat (sz.height, sz.width, CvType.CV_8U) I replace the problematic line; Raw.put (0, 0, data); Mat targ = highigiimd code (raw, 0);   

I can get a grayscale image what I am doing

  mat raw = new mat (sz.height, sz.width, cvType.CV_8UC3 );   

? I have seen some stackoverflow positions, which address it and there is no work for color matrix. I have appreciated any help very much.

I have found an alternative solution for this: From the bitmap factory, you can convert bytes [ ] Arrays for a bitmap, which you can alternately convert to a mat.

  Bitmap BMP = BitMapFactory. Decodedbitiera (data, 0, data. Length); Mat orig = new met (bmp.getHeight (), bmp.getWidth (), CvType.CV_8UC3); Bitmap myBitmap32 = bmp.copy (bitmap config.argb_8888, true); Utils.bitmapToMat (myBitmap32, orig); Imgproc.cvtColor (orig, orig, imgproc. COLOR_BGR2RGB, 4);   

It seems that there should be a better way but it works.

Comments

Popular posts from this blog

Verilog Error: output or inout port "Q" must be connected to a structural net expression -

jasper reports - How to center align barcode using jasperreports and barcode4j -

c# - ASP.NET MVC - Attaching an entity of type 'MODELNAME' failed because another entity of the same type already has the same primary key value -