我正在开发Android应用程序,我想使用Harris角点检测。我想绘制检测到的角落,但我似乎无法找到Java代码的文档。
到目前为止我的代码:
Mat inputImage = inputFrame.rgba();
Imgproc.cornerHarris(inputImage, inputImage, 7, 5, 0.05, Imgproc.BORDER_DEFAULT);
如何检测并显示角落?
答案 0 :(得分:2)
对于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);
}
}
}
}
我刚刚编写了以下代码here
答案 1 :(得分:0)
我知道这不是理想的,但它也不是那么糟糕 - 你可以查看c ++文档和示例,Java的翻译通常是直截了当的: 一个例子:Harris corner detector。 (你没有提到你的版本,这是从v2.4开始的。)
答案 2 :(得分:0)
如果仍在寻找OpenCV Java示例,则可以在以下链接中找到它。
完成Java示例
https://github.com/opencv/opencv/tree/master/samples/java/tutorial_code
运动跟踪
https://github.com/opencv/opencv/tree/master/samples/java/tutorial_code/TrackingMotion
哈里斯拐角检测