誰かが私にそれを解決するのを助けることができますか?私は、Watershed Segmentation、私の問題、Image内のContourとCountObjectの発見方法についてバイナリイメージを持っていますか?バイナリイメージのFindContoursとCountObject
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
if (requestCode == RESULT_LOAD_IMAGE && resultCode == RESULT_OK && null != data) {
Uri selectedImage = data.getData();
String[] filePathColumn = { MediaStore.Images.Media.DATA };
Cursor cursor = getContentResolver().query(selectedImage,
filePathColumn, null, null, null);
cursor.moveToFirst();
int columnIndex = cursor.getColumnIndex(filePathColumn[0]);
String picturePath = cursor.getString(columnIndex);
cursor.close();
ImageView imageView = (ImageView) findViewById(R.id.imgView);
Bitmap bmp=BitmapFactory.decodeFile(picturePath);
Log.i(TAG, picturePath);
Mat img=Highgui.imread(picturePath);
//Mat img=Imgcodecs.imread(picturePath);
Mat result=new Mat();
//Utils.bitmapToMat(bmp, img);
//Imgproc.cvtColor(img,result,Imgproc.COLOR_BGRA2BGR);
result=steptowatershed(img);
//Imgproc.cvtColor(result, img,Imgproc.COLOR_BGR2BGRA,4);
Utils.matToBitmap(result, bmp, true);
Log.i(TAG, "all okay");
imageView.setImageBitmap(bmp);
}
}
//in here i must place that code for findContours and Count object ? or where ?
public Mat steptowatershed(Mat img)
{
Mat threeChannel = new Mat();
Imgproc.cvtColor(img, threeChannel, Imgproc.COLOR_BGR2GRAY);
Imgproc.threshold(threeChannel, threeChannel, 100, 255, Imgproc.THRESH_BINARY);
Mat fg = new Mat(img.size(),CvType.CV_8U);
Imgproc.erode(threeChannel,fg,new Mat());
Mat bg = new Mat(img.size(),CvType.CV_8U);
Imgproc.dilate(threeChannel,bg,new Mat());
Imgproc.threshold(bg,bg,1, 128,Imgproc.THRESH_BINARY_INV);
Mat markers = new Mat(img.size(),CvType.CV_8U, new Scalar(0));
Core.add(fg, bg, markers);
Mat result1=new Mat();
WatershedSegmenter segmenter = new WatershedSegmenter();
segmenter.setMarkers(markers);
result1 = segmenter.process(img);
return result1;
//in here i must place that code for findContours and Count object ? or where ?
}
public class WatershedSegmenter
{
public Mat markers=new Mat();
public void setMarkers(Mat markerImage)
{
markerImage.convertTo(markers, CvType.CV_32SC1);
}
//in here i must place that code for findContours and Count object ? or where ?
public Mat process(Mat image)
{
Imgproc.watershed(image,markers);
markers.convertTo(markers,CvType.CV_8U);
return markers;
}
}
@pigletは何ですか?どこでそのようなオブジェクトを数えることができるコードを置く必要がありますか?上の私のソースコードですか? – MTStuart
私たちは@Pigletをチャットできますか? – MTStuart
あなたのソースコードを十分に理解できない場合は、それらの関数呼び出しを追加する場所を知っていなければ、既に何を持っているかを理解することができます。 3つの関数すべてのドキュメントをお読みください。これはまともなプログラマが最初にやることです。私はあなたがここで何をしているのか理解していないと仮定します。そうでなければ、呼び出しの順序ははっきりします。あなたの母親に説明するように、あなたのコード全体にコメントを書くことから始めます。何が起こっている?あなたはどのようなデータを持っていますか... ... – Piglet