[英]OpenCV Java Harris Corner Detection
I am developing an Android application and I want to make use of Harris corner detection. 我正在开发一个Android应用程序,并且想利用Harris角点检测。 I want to draw the corners detected but I cannot seem to find the documentation for the Java code.
我想画出检测到的角落,但似乎找不到Java代码的文档。
My code so far: 到目前为止,我的代码:
Mat inputImage = inputFrame.rgba();
Imgproc.cornerHarris(inputImage, inputImage, 7, 5, 0.05, Imgproc.BORDER_DEFAULT);
How can I detect and display the corners? 如何检测和显示角落?
For Java you can try this piece of code. 对于Java,您可以尝试这段代码。
private void Harris(Mat Scene, Mat Object, int thresh) {
// This function implements the Harris Corner detection. The corners at intensity > thresh
// are drawn.
Mat Harris_scene = new Mat();
Mat Harris_object = new Mat();
Mat harris_scene_norm = new Mat(), harris_object_norm = new Mat(), harris_scene_scaled = new Mat(), harris_object_scaled = new Mat();
int blockSize = 9;
int apertureSize = 5;
double k = 0.1;
Imgproc.cornerHarris(Scene, Harris_scene,blockSize, apertureSize,k);
Imgproc.cornerHarris(Object, Harris_object, blockSize,apertureSize,k);
Core.normalize(Harris_scene, harris_scene_norm, 0, 255, Core.NORM_MINMAX, CvType.CV_32FC1, new Mat());
Core.normalize(Harris_object, harris_object_norm, 0, 255, Core.NORM_MINMAX, CvType.CV_32FC1, new Mat());
Core.convertScaleAbs(harris_scene_norm, harris_scene_scaled);
Core.convertScaleAbs(harris_object_norm, harris_object_scaled);
for( int j = 0; j < harris_scene_norm.rows() ; j++){
for( int i = 0; i < harris_scene_norm.cols(); i++){
if ((int) harris_scene_norm.get(j,i)[0] > thresh){
Imgproc.circle(harris_scene_scaled, new Point(i,j), 5 , new Scalar(0), 2 ,8 , 0);
}
}
}
for( int j = 0; j < harris_object_norm.rows() ; j++){
for( int i = 0; i < harris_object_norm.cols(); i++){
if ((int) harris_object_norm.get(j,i)[0] > thresh){
Imgproc.circle(harris_object_scaled, new Point(i,j), 5 , new Scalar(0), 2 ,8 , 0);
}
}
}
}
I know this is not ideal, but it is also not so bad - you can look at the c++ documentation and examples, the translation to Java is usually straight forward: One example: Harris corner detector . 我知道这并不理想,但是也还不错-您可以查看c ++文档和示例,通常直接翻译成Java:一个示例: Harris角落检测器 。 (you did not mention your version, this is from v2.4).
(您没有提到您的版本,这是来自v2.4的版本)。
If anyone is still looking for OpenCV Java Samples, you can find it here in the following links. 如果仍有人在寻找OpenCV Java示例,则可以在以下链接中找到它。
Complete Java Samples 完整的Java示例
https://github.com/opencv/opencv/tree/master/samples/java/tutorial_code https://github.com/opencv/opencv/tree/master/samples/java/tutorial_code
Motion Tracking 运动追踪
https://github.com/opencv/opencv/tree/master/samples/java/tutorial_code/TrackingMotion https://github.com/opencv/opencv/tree/master/samples/java/tutorial_code/TrackingMotion
Harris Corner Detection 哈里斯角检测
https://github.com/opencv/opencv/blob/master/samples/java/tutorial_code/TrackingMotion/harris_detector/CornerHarrisDemo.java https://github.com/opencv/opencv/blob/master/samples/java/tutorial_code/TrackingMotion/harris_detector/CornerHarrisDemo.java
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.