0

我已经尝试使用我的代码从相机拍照并将其从 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);

  }
  }
 }
4

1 回答 1

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

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

您需要将 HSV 从 3 通道转换为 4 通道,因为 Android 无法在 3 通道中显示 Mat。有关更多信息,请参阅此内容。

于 2015-02-23T20:28:38.430 回答