# thresholding public Mat [] thresholding(img){ Mat frame = img.rgba(); //Imgproc.cvtColor(frame, frame, Imgproc.COLOR_RGBA2GRAY); //Imgproc.Canny(frame, frame, 100, 80); //RGB灰化 //Mat copyImg = new Mat(); //frame.copyTo(copyImg, img); Imgproc.cvtColor(frame, frame,Imgproc.COLOR_BGR2GRAY); Mat kernel =new Mat (5,5, CvType.CV_32F); kernel.put(0, 0, new float[]{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}); //平滑處理 Imgproc.GaussianBlur(frame, frame, new Size(5, 5),0, 0, Core.BORDER_DEFAULT); //輪廓 //使用Canny檢測邊緣 double lowThresh =80;//雙閥執抑制中的低閥值 double heightThresh = 100;//雙閥執抑制中的高閥值 Imgproc.Canny(frame, frame,lowThresh, heightThresh); //回傳值imgCanny Mat imgCanny = new Mat(); frame.copyTo(imgCanny, frame); Mat element = Imgproc.getStructuringElement(Imgproc.MORPH_RECT, new Size(3,3)); //膨脹 Imgproc.dilate(frame, kernel, element, new Point(-1, -1), 1); //腐蝕 Imgproc.erode(frame, kernel, element, new Point(-1, -1), 1); Mat imgColor = colorFilter(img); Mat combinedImage = new Mat(); Core.bitwise_or(imgColor, frame , combinedImage); Mat returnImg [] = new Mat [3]; returnImg[0] = combinedImage; returnImg[1] = imgCanny; returnImg[2] = imgColor; return returnImg; } # get_hist //不知道img怎麼寫成三圍 public double[] get_hist(Mat img){ double hist [][] = new double[img.cols()/2][img.rows()] ; for(int i = 0 ; i < img.cols()/2 ; i++){ for(int j = 0 ; j < img.rows() ; j++){ hist[i][j] = img[i][j][0] + img[i][j][1] + img[i][j][2]; } } //hist[] 81600 } # textDisplay //沒人呼叫 public void textDisplay(int curve,Mat img){ String directionText = new String(); Imgproc.putText(img, curve+"" , ((img.rows()/2)-30, 40), Core.FONT_HERSHEY_SIMPLEX, 1.0, new Scalar(255,0,0)); //原程式碼cv2.putText(img, str(curve), ((img.shape[1]//2)-30, 40), font, 1, (255, 255, 0), 2, cv2.LINE_AA); //cv2.putText(影像, 文字, 座標, 字型, 大小, 顏色, 線條寬度, 線條種類) directionText=" No lane "; if(curve > 10){ directionText="Right"; } else if (curve < -10){ directionText="Left"; } else if (curve <10 && curve > -10){ directionText="Straight"; } else if (curve == -1000000){ directionText = "No Lane Found"; } Imgproc.putText(img, directionText, ((img.rows()/2)-35,(img.cols()-20 ), Core.FONT_HERSHEY_SIMPLEX, 1.0, new Scalar(0,200,200)); //原程式碼cv2.putText(img, directionText, ((img.shape[1]//2)-35,(img.shape[0])-20 ), font, 1, (0, 200, 200), 2, cv2.LINE_AA) //curve的值不知道是從哪傳來的 主程式跟副程式好像沒人呼叫這個副程式 } # pipeline //沒人呼叫 //開始用sobel後的np.不會寫