3C科技 娛樂遊戲 美食旅遊 時尚美妝 親子育兒 生活休閒 金融理財 健康運動 寰宇綜合

Zi 字媒體

2017-07-25T20:27:27+00:00
加入好友
此篇只使用霍夫曼圓公式找圓 Bitmap圖片取得方法請看這篇: Bitmap圖片繪製篇 OPENCV安裝請看這篇: OPENCV安裝 示範 JAVA Bitmapp = ((BitmapDrawable) ig.getDrawable()).getBitmap();//取得Bitmap圖片 Utils.bitmapToMat(Bitmapp, mat);//將bitmap圖片轉換成Mat格式 Imgproc.cvtColor(mat, grayMat, Imgproc.COLOR_RGB2GRAY);//將彩度圖轉化為灰度圖PS:霍夫曼規定要用灰度圖 double dp = 1;//辨識率1是最大 double minDist = 10;//最小同心圓距離 double param1 = 100;//圓半徑包含的Pixel值上限 double param2 = 50;//圓半徑包含的Pixel值下限 int minRadius = 10;//最小元半徑範圍 int maxRadius = 20;//最大元半徑範圍 Mat circles = new Mat(Bitmapp.getWidth(), Bitmapp.getHeight(), CvType.CV_8UC1);//創建Mat畫布,寬和高依照Bitmap圖片 Imgproc.HoughCircles(grayMat, circles, Imgproc.CV_HOUGH_GRADIENT, dp, minDist, param1, param2, minRadius, maxRadius);//霍夫曼圓公式 int radius = 0; //利用迴圈找出圖片中的圓 if (circles.cols() != 0) { try { for (int ig = 0; ig <= Math.min(circles.cols(), 100); ig++) {//可以控制要抓出的圓數量 double circleVec[] = circles.get(0, ig); Point center = new Point((int) circleVec[0], (int) circleVec[1]);//圓心 radius = (int) circleVec[2];//圓周 Imgproc.circle(mat, center, radius, new Scalar(255, 255, 0), 1);//畫圓周(MAT畫布/圓心/圓周/顏色/粗細) Imgproc.circle(mat, center, 1, new Scalar(100, 100, 50), 1);//畫圓心(MAT畫布/圓心/圓周/顏色/粗細) } //try{}catch()必加不可省略 } catch (Exception e) { } } Utils.matToBitmap(mat, Bitmapp);//轉換Mat圖片回Bitmap圖片 ig.setImageBitmap(Bitmapp);//設置Bitmap圖片到ImageView元件裡面   展示   相關文章: [Android] Android 學習總集

本文由kk665403pixnetnetblog提供 原文連結

寫了 5860316篇文章,獲得 23313次喜歡
精彩推薦