使用Opencv的RGB到HSV颜色转换android

时间:2012-11-14 05:57:55

标签: android image-processing opencv colors hsv

我已经尝试过我的代码从相机拍摄照片并将其转换为RGB的HSV色彩空间, 但结果没有显示HSV颜色,它显示出一些不寻常的东西, 请看一下 这是我的代码

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);

  }
  }
 }

1 个答案:

答案 0 :(得分:0)

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

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

您需要将HSV从3个频道转换为4个频道,因为Android无法在3个频道中显示Mat。有关详细信息,请参阅此处。