Java|Java OpenCV-4.0.0 图像处理33 视频分析和对象跟踪 角点检测


Java OpenCV-4.1.0 图像处理33 视频分析和对象跟踪 角点检测
【Java|Java OpenCV-4.0.0 图像处理33 视频分析和对象跟踪 角点检测】

package com.xu.opencv.video; import org.opencv.core.Core; import org.opencv.core.Mat; import org.opencv.core.MatOfPoint; import org.opencv.core.Point; import org.opencv.core.Scalar; import org.opencv.highgui.HighGui; import org.opencv.imgproc.Imgproc; import org.opencv.videoio.VideoCapture; /** * * @ClassName: Corner * @Description: TODO * @author: hyacinth * @date: 2019年7月21日 下午6:23:30 * @Copyright: hyacinth */ public class Corner { MatOfPoint corners=new MatOfPoint(); static { System.loadLibrary(Core.NATIVE_LIBRARY_NAME); } public static void main(String[] args) { Corner corner=new Corner(); corner.corners(); } /** *OpenCV-4.0.0 视频分析和对象跟踪 角点检测与绘制 * @Title: corners * @Description: TODO * @param: * @return: void * @date: 2019年7月21日 下午6:28:51 * @throws */ private void corners() { // 1 创建 VideoCapture 对象 VideoCapture capture=new VideoCapture(); // 2 使用 VideoCapture 对象读取本地视频 capture.open("C:\\Users\\hyacinth\\Videos\\111.mp4"); // 3 获取视频处理时的键盘输入 我这里是为了在 视频处理时如果按 Esc 退出视频对象跟踪 int index=0; Mat video=new Mat(); Mat gray=new Mat(); int maxCorners=5000; double qualityLevel=0.01; int minDistance=10; int blockSize=3; int gradientSize=5; double k=0.04; while (capture.read(video)) { Imgproc.cvtColor(video, gray, Imgproc.COLOR_BGR2GRAY); Imgproc.goodFeaturesToTrack(gray, corners, maxCorners, qualityLevel, minDistance, new Mat(), blockSize, gradientSize, false, k); drawCorners(video,corners); HighGui.imshow("角点检测", video); index=HighGui.waitKey(1); if (index==27) { capture.release(); return; } } } /** * OpenCV-4.0.0 视频分析和对象跟踪 绘制角点 * @Title: drawFeatures * @Description: TODO * @param: @param mat * @param: @param corners MatOfPoint * @return: void Mat * @date: 2019年7月21日 下午4:00:53 * @throws */ private void drawCorners(Mat mat,MatOfPoint corners) { int[] cornersData = https://www.it610.com/article/new int[(int) (corners.total() * corners.channels())]; corners.get(0, 0, cornersData); for (int i = 0; i < corners.rows(); i++) { Imgproc.circle(mat, new Point(cornersData[i * 2], cornersData[i * 2 + 1]), 2, new Scalar(0, 0,255), Imgproc.FILLED); } }}

Java|Java OpenCV-4.0.0 图像处理33 视频分析和对象跟踪 角点检测
文章图片

    推荐阅读