先说一个通用的规则,个人理解
CV::
对象,在Java是Core
(org.opencv.core.Core)Imgproc
(org.opencv.imgproc.Imgproc)在OpenCV中图片被存储在Mat(org.opencv.core)
容器中
Size size = new Size(720,680);
Mat dstMat= new Mat();
/**
* srcMat 原图,dstMat目标,size裁剪后大小
*/
Imgproc.resize(srcMat, dstMat, size);
srcMat.release();
srcMat = dstMat; //释放资源
Mat dstMat= new Mat();
//旋转90°
int angle = 90;
Imgproc.warpAffine(srcMat, dstMat, Imgproc.getRotationMatrix2D(new Point(dstMat.width() / 2, dstMat.height() / 2), angle, 1.0), size);
srcMat.release();
srcMat= dstMat;
Mat dstMat= new Mat();
/**
* srcMat 原图,dstMat目标,
* opencv翻转:
* flipCode:
* = 0 图像向下翻转 (垂直翻转)
* > 0 图像向右翻转(水平翻转)
* < 0 图像同时向下向右翻转 (水平垂直翻转)
*/
Core.flip(srcMat, dstMat, mode);
srcMat.release();
srcMat = dstMat; //释放资源
//这里的顺序是GBR,不是RGB
Scalar color = new Scalar(0,0,255);
//矩形框
Rect rect = new Rect(0,0,100,100;
Imgproc.rectangle(mat, rect,color );
//这里的顺序是GBR,不是RGB
Scalar color = new Scalar(0,0,255);
//矩形框
Rect rect = new Rect(0,0,100,100;
Imgproc.putText(mat, "Hello", new Point(rect.x, rect.y), FONT_HERSHEY_SIMPLEX, 1,color);
如果要显示中文好像要添加底层的依赖库,暂时没弄
Scalar color = new Scalar(0,0,255);
Rect rect = new Rect(0,0,100,100;
Imgproc.line(mat, new Point(rect.x, rect.y), new Point(rect.x + rect.width, rect.y + rect.height), color );