如何将python中的定位代码转换为kotlin?

如何将python中的定位代码转换为kotlin?,第1张

如何将python中的定位代码转换为kotlin?
//Load the imagesrcOriginal = Imgprecs.imread(currentPhotoPath)//Create a blank image of zeros (same dimension as img)//It should be grayscale (1 color channel)markers = Mat.zeros(srcOriginal.rows(), srcOriginal.cols(), CvType.CV_32S)//This step is manual. The goal is to find the points//which create the result we want. I suggest using a//tool to get the pixel coordinates.//Dictate the background and set the markers to 1for (value in 0..my_canvas.pointsToDrawY.size - 1) {        markers.put( my_canvas.pointsToDrawX[value].toInt(), my_canvas.pointsToDrawY[value].toInt(), 1.0       )}//Dictate the area of interest//I used different values for each part of the car (for visibility)for (value in 0..my_canvas.pointsToDrawYStepTwo.size - 1) {        markers.put( my_canvas.pointsToDrawXStepTwo[value].toInt(), my_canvas.pointsToDrawYStepTwo[value].toInt(), 255.0        )}//Now we have set the markers, we use the watershed//algorithm to generate a marked imagewatershed(srcOriginal, markers)//Plot this one. If it does what we want, proceed;//otherwise edit your markers and repeatval mPath1 = Environment.getExternalStorageDirectory().toString() + "/watershed.png"    Imgprecs.imwrite(mPath1,markers)//Make the background black, and what we want to keep whitefor (x in 0 until srcOriginal.rows()-1) {        for (y in 0 until srcOriginal.cols()-1) { if(markers.get(x,y).get(0).equals(1.0)){     markers.put(         x,         y,         0.0     ) } if((markers[x, y].get(0) == 255.0)){     markers.put(         x,         y,         255.0     ) }        }    }//Use a kernel to dilate the image, to not lose any detail on the outline//I used a kernel of 3x3 pixelsval marker_tempo = Mat()val dilatation = Mat()markers.convertTo(marker_tempo, CvType.CV_8U)val kernel = Mat(3, 3, CvType.CV_8U)Imgproc.dilate(marker_tempo, dilatation, kernel)//Plot again to check whether the dilation is according to our needs//If not, repeat by using a smaller/bigger kernel, or more/less iterationsval mPath2 = Environment.getExternalStorageDirectory().toString() + "/dilatation.png"Imgprecs.imwrite(mPath2,dilatation)//Now apply the mask we created on the initial imageval final = Mat()Core.bitwise_and(srcOriginal, srcOriginal, final, dilatation)//Plot the final resultval mPath = Environment.getExternalStorageDirectory().toString() + "/final.png"Imgprecs.imwrite(mPath,final)


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5565731.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-14
下一篇 2022-12-14

发表评论

登录后才能评论

评论列表(0条)

保存