opencv3_java 图像透视视角转换Perspective warpPerspective
2017-05-31 21:22
561 查看
图像透视视角转换Perspective warpPerspective
package opencv_java_demo; import java.util.List; import org.opencv.core.*; import org.opencv.imgcodecs.*; import org.opencv.imgproc.*; import org.opencv.utils.Converters; public class Perspective { public static void main(String[] args) { try{ System.loadLibrary(Core.NATIVE_LIBRARY_NAME); Mat src=Imgcodecs.imread("./images/lenna.jpg"); //读取图像到矩阵中 if(src.empty()){ throw new Exception("no file"); } int xMargin,yMargin; int x0=src.cols()/4; int x1=(src.cols()/4)*3; int y0=src.cols()/4; int y1=(src.cols()/4)*3; Mat dst=new Mat(); List<Point> listSrcs=java.util.Arrays.asList(new Point(x0,y0),new Point(x0,y1),new Point(x1,y1),new Point(x1,y0)); Mat srcPoints=Converters.vector_Point_to_Mat(listSrcs,CvType.CV_32F); xMargin=src.cols()/10; yMargin=src.rows()/10; List<Point> listDsts=java.util.Arrays.asList(new Point(x0+xMargin,y0+yMargin),listSrcs.get(1),listSrcs.get(2),new Point(x1-xMargin,y0+yMargin)); Mat dstPoints=Converters.vector_Point_to_Mat(listDsts,CvType.CV_32F); Mat perspectiveMmat=Imgproc.getPerspectiveTransform(srcPoints, dstPoints); Imgproc.warpPerspective(src, dst, perspectiveMmat, src.size(),Imgproc.INTER_LINEAR); Imgcodecs.imwrite("./images/dst0.jpg",dst); xMargin=src.cols()/8; yMargin=src.cols()/8; listDsts.set(0, listSrcs.get(0)); listDsts.set(1, listSrcs.get(1)); listDsts.set(2, new Point(x1-xMargin,y1-yMargin)); listDsts.set(3, new Point(x1-xMargin,y0-yMargin)); dstPoints=Converters.vector_Point_to_Mat(listDsts,CvType.CV_32F); perspectiveMmat=Imgproc.getPerspectiveTransform(srcPoints, dstPoints); Imgproc.warpPerspective(src, dst, perspectiveMmat, src.size(),Imgproc.INTER_LINEAR); Imgcodecs.imwrite("./images/dst1.jpg", dst); xMargin=src.cols()/6; yMargin=src.cols()/6; listDsts.set(0, new Point(x0+xMargin,y0+yMargin)); listDsts.set(1, listSrcs.get(1)); listDsts.set(2, new Point(x1-xMargin,y1-yMargin)); listDsts.set(3, listSrcs.get(3)); dstPoints=Converters.vector_Point_to_Mat(listDsts,CvType.CV_32F); perspectiveMmat=Imgproc.getPerspectiveTransform(srcPoints, dstPoints); Imgproc.warpPerspective(src, dst, perspectiveMmat, src.size(),Imgproc.INTER_LINEAR); Imgcodecs.imwrite("./images/dst2.jpg", dst); }catch(Exception e){ System.out.println("例外:" + e); } } }
相关文章推荐
- opencv之透视变换cvWarpPerspective
- opencv之WarpPerspective透视变化
- 两个openCV补充函数。用于不同位数图像之间转换的。。
- opencv常用转换 opencv图像处理
- 如何用JAVA转换图像格式
- OpenCV 矩阵 到 图像 转换
- OpenCV实现彩色图像转换为灰度图及二值化处理
- 使用 Java 进行图像处理 - 将彩色图像转换为灰度图
- C++ OpenCV 实现RGB彩色图像转化成灰度图像再转换成二值图像
- 关于OpenCV中利用函数cvConvert实现图像数据类型转换(8U->16S)
- OpenCv,EmguCv及.net之间的图像类型转换
- ImagesUtil java图片操作 缩放图像、切割图像、图像类型转换、彩色转黑白、文字水印、图片水印等
- OPENCV应用中BMP与IPLIAMGE图像格式的相互转换
- OpenCV与Qt 中图像格式的转换
- opencv--转换图像大小
- OPENCV应用中BMP与IPLIAMGE图像格式的相互转换及源代码
- OpenCV 中的图像结构IPLImage 和 Qt中QImage之间的转换源代码
- 转:OpenCV中IplImage图像格式与 BYTE图像数据的转换
- C# OpenCV学习笔记三之图像捕捉及其灰度转换方法
- RGB彩色图像与灰度图像转换 opencv实现 代码及分析