0

i've tried my code to take a picture from camera and convert it into a HSV color space from RGB, but the result didn't show the HSV color, it shows something unusual, please take a look here's my code

public void onCreate(Bundle savedInstanceState) {
   super.onCreate(savedInstanceState);
   setContentView(R.layout.main);
   Button buttonImageCapture = (Button)findViewById(R.id.captureimage);
   imageiewImageCaptured = (ImageView)findViewById(R.id.imagecaptured);

   buttonImageCapture.setOnClickListener(buttonImageCaptureOnClickListener);
}

Button.OnClickListener buttonImageCaptureOnClickListener
= new Button.OnClickListener(){

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Intent intent = new Intent(android.provider.MediaStore.ACTION_IMAGE_CAPTURE);
startActivityForResult(intent, 0);

}};

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
// TODO Auto-generated method stub
super.onActivityResult(requestCode, resultCode, data);
//try{
if (resultCode == RESULT_OK)
{
Bundle extras = data.getExtras();
Bitmap bmp = (Bitmap) extras.get("data");

bmp = bmp.copy(Bitmap.Config.ARGB_8888, true);
Mat newmat = Utils.bitmapToMat(bmp);


Mat mHSV = new Mat();
Imgproc.cvtColor(newmat, mHSV, Imgproc.COLOR_BGR2HSV,3);

Bitmap newbmp = Bitmap.createBitmap(newmat.cols(), newmat.rows(), Bitmap.Config.ARGB_8888);
Utils.matToBitmap(mHSV, newbmp);

imageiewImageCaptured.setImageBitmap(newbmp);

  }
  }
 }
Noha Kareem
  • 1,748
  • 1
  • 22
  • 32
user1802057
  • 125
  • 1
  • 2
  • 4
  • What is your expectation of the appearance of an HSV image? Do you want it to map Hue to Red, Saturation to Green and Value to Blue? If so, the results will look very awkward but will be understandable to an imaging scientist. If you convert HSV back to RGB for viewing, then you get back the original image. – rwong Nov 14 '12 at 06:11
  • actually i just want to look the appearance of an HSV image itself, i've tried it in MATLAB, so i know the HSV color looks like, but i want to know it in Android, but thanks :D – user1802057 Nov 14 '12 at 06:27
  • The thing is, "it shows something unusual" doesn't really make for a good definition of your problem. Is the image skewed or otherwise malformed, or do the pixels simply have unexpected colors? A screenshot of both the expected (same image in MATLABL) and achieved images might work wonders for this question. – Paul-Jan Nov 14 '12 at 06:43

1 Answers1

0
Imgproc.cvtColor(rgba, mhsv , Imgproc.COLOR_RGB2HSV_FULL);

        Imgproc.cvtColor(mhsv, rgba, Imgproc.COLOR_RGB2RGBA);

you need to Convert HSV from 3 Channel to 4 Channel because Android cannot display Mat in 3 Channel. See this for more Information.

Murad
  • 383
  • 1
  • 7