java opencv绘制工字型
package com.vfsd.core; import java.util.ArrayList; import java.util.List; import org.opencv.core.Core; import org.opencv.core.CvType; import org.opencv.core.Mat; import org.opencv.core.Point; import org.opencv.core.Rect; import org.opencv.core.Scalar; import org.opencv.highgui.HighGui; import org.opencv.imgproc.Imgproc; public class Test4 { public static void main( String[] args ) { System.loadLibrary( Core.NATIVE_LIBRARY_NAME ); Scalar scalar1 = new Scalar(0,0,0); Mat img1 = new Mat(360,840,CvType.CV_8UC3,scalar1); List<Integer> list1_points = new ArrayList<Integer>(); list1_points.add(50); list1_points.add(50); list1_points.add(70); list1_points.add(70); drawPolygonShape(img1,list1_points,0,0,1); List<Integer> list2_points = new ArrayList<Integer>(); list2_points.add(50); list2_points.add(50); list2_points.add(150); list2_points.add(50); list2_points.add(150); list2_points.add(70); list2_points.add(110); list2_points.add(70); list2_points.add(110); list2_points.add(200); list2_points.add(150); list2_points.add(200); list2_points.add(150); list2_points.add(220); list2_points.add(50); list2_points.add(220); list2_points.add(50); list2_points.add(200); list2_points.add(90); list2_points.add(200); list2_points.add(90); list2_points.add(70); list2_points.add(50); list2_points.add(70); drawPolygonShape(img1,list2_points,50,50,2); drawPolygonShape(img1,list2_points,250,50,2); drawPolygonShape(img1,list2_points,450,50,2); HighGui.imshow("win1", img1); HighGui.waitKey(); } public static void drawPolygonShape(Mat img1,List<Integer> list_points,int center_x,int center_y,int shape_type) { Scalar scalar2 = new Scalar(0,0,255); //矩形 if(shape_type==1) { Rect rect1 = new Rect(new Point(list_points.get(0),list_points.get(1)),new Point(list_points.get(2),list_points.get(3))); Imgproc.rectangle(img1,rect1 , scalar2); } //多边形 else if(shape_type==2) { for(int k=0;k<list_points.size();k+=2){ if(k<list_points.size()-2) { int point1_x = list_points.get(k+0)+center_x; int point1_y = list_points.get(k+1)+center_y; int point2_x = list_points.get(k+2)+center_x; int point2_y = list_points.get(k+3)+center_y; Imgproc.line(img1,new Point(point1_x,point1_y),new Point(point2_x,point2_y),scalar2,1); }else { int point1_x = list_points.get(0)+center_x; int point1_y = list_points.get(1)+center_y; int point2_x = list_points.get(list_points.size()-2)+center_x; int point2_y = list_points.get(list_points.size()-1)+center_y; Imgproc.line(img1,new Point(point1_x,point1_y),new Point(point2_x,point2_y),scalar2,1); } } } } }
###############################
标签:工字型,java,50,list2,opencv,add,points,import From: https://www.cnblogs.com/herd/p/17578323.html