栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

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

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何将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)


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/574492.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号