Quantcast
Channel: OpenCV Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 41027

How to get xpos and ypos value using FindContours

$
0
0
Hello I'm trying to recognize image contours using OpenCV4 with Android Studio(kotlin). However, I don't know how to get xpos and ypos value from MatOfPoint variables. ( MatOfPoint variables is output of Imgproc.FindContours ) Do you have any solutions ? private fun calcPosXY(){ val bitmap = textureView.getBitmap() var imageMat = Mat() val contours = ArrayList() val hierarchy = Mat() Utils.bitmapToMat(bitmap, imageMat) Imgproc.cvtColor(imageMat,imageMat,Imgproc.COLOR_RGB2GRAY) Imgproc.threshold(imageMat, imageMat, 100.0, 255.0, Imgproc.THRESH_BINARY) Imgproc.findContours(imageMat, contours, hierarchy, Imgproc.RETR_EXTERNAL,Imgproc.CHAIN_APPROX_TC89_L1) for (contour in contours) { val approxCurve = MatOfPoint2f() val contour2f = MatOfPoint2f() contour.convertTo(contour2f,CvType.CV_32FC2) val approxDistance = Imgproc.arcLength(contour2f,true) * 0.02 Imgproc.approxPolyDP(contour2f,approxCurve,approxDistance,true) val points = MatOfPoint() //this variable approxCurve.convertTo(points,CvType.CV_8UC4) // // how to get xpos and ypos value from each points? // e.g. xpos=327 ypos= 512 // } }

Viewing all articles
Browse latest Browse all 41027

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>