1 | initial version |
Actually i am found answer:
Mat src = new Mat( im.getHeight(), im.getWidth(), CvType.CV_8UC1 ); src.put( 0, 0, ( ( DataBufferByte ) im.getRaster().getDataBuffer() ).getData() ); List< MatOfPoint > contours = new ArrayList<>(); Imgproc.findContours( src, contours, new Mat(), Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE, new Point( 0, 0 ) ); for ( MatOfPoint point: contours ) { MatOfPoint2f source = new MatOfPoint2f(); point.convertTo( source, CvType.CV_32F ); MatOfPoint2f gb= new MatOfPoint2f(); Imgproc.GaussianBlur( source, gb, new Size( 3, 3 ), 0, 0 ); Polygon polygon = new Polygon(); gb.toList().stream().forEach( p -> polygon.addPoint( ( int ) p.x, ( int ) p.y ) ); ........
2 | No.2 Revision |
Actually i am found answer:
BufferedImage result = new BufferedImage( im.getHeight(), im.getWidth(), TYPE_INT_RGB );
g2.createGraphics();
Mat src = new Mat( im.getHeight(), im.getWidth(), CvType.CV_8UC1 );
....
3 | No.3 Revision |
Actually i am found answer:
BufferedImage result = new BufferedImage( im.getHeight(), im.getWidth(), TYPE_INT_RGB );
g2.createGraphics();
Mat src = new Mat( im.getHeight(), im.getWidth(), CvType.CV_8UC1 );
src.put( 0, 0, ( ( DataBufferByte ) im.getRaster().getDataBuffer() ).getData() );
List< MatOfPoint > contours = new ArrayList<>();
Imgproc.findContours( src, contours, new Mat(), Imgproc.RETR_TREE, Imgproc.CHAIN_APPROX_SIMPLE, new Point( 0, 0 ) );
for ( MatOfPoint point: contours ) {
MatOfPoint2f source = new MatOfPoint2f();
point.convertTo( source, CvType.CV_32F );
MatOfPoint2f gb= new MatOfPoint2f();
Imgproc.GaussianBlur( source, gb, new Size( 3, 3 ), 0, 0 );
Polygon polygon = new Polygon();
gb.toList().stream().forEach( p -> polygon.addPoint( ( int ) p.x, ( int ) p.y ) );
g2.setColor( Color.WHITE);
....