如何使用OpenCV从canny边缘检测中找到x和y位置?

时间:2018-05-08 08:40:30

标签: android opencv edge-detection

我试图从canny边缘检测转换后找到图像的x和y位置,但我无法找到准确的结果。我正在使用opencvlibrary311。

这是我的代码段。

// transformation matrix
Mat transformMatrix = Imgproc.getPerspectiveTransform(srcMat, dstMat);

finalMat = Mat.zeros((int) maxHeight, (int) maxWidth, CvType.CV_32FC2);
Imgproc.warpPerspective(rgbMat, finalMat, transformMatrix, finalMat.size());
Log.e("FinalDisplay", "finalMat: " + finalMat.size());

// display final results
Bitmap dstBitmap = Bitmap.createBitmap(finalMat.width(), finalMat.height(), Bitmap.Config.RGB_565);
Log.e("FinalDisplay", "dstBitmap: " + img.getWidth() + " x " + img.getHeight());
Utils.matToBitmap(finalMat, dstBitmap); //convert mat to bitmap

// create cropped bitmap based on canny edge x and y and height and width
try {
    Bitmap crop = Bitmap.createBitmap(rotateandscalebitmap, cannyMat.rows(),cannyMat.cols(), dstBitmap.getWidth(), dstBitmap.getHeight()-20);
    // Bitmap crop = Bitmap.createBitmap(rotateandscalebitmap, ((int) horizontals.get(5)._center.y + 150), ((int) verticals.get(0)._center.x), dstBitmap.getWidth() + 100, dstBitmap.getHeight() + 10);

    croppedbitmap = crop;
    doRecognize(croppedbitmap);

} catch (Exception e) {
    e.printStackTrace();
}

我想要输出

enter image description here

0 个答案:

没有答案