这是我的代码,我收到错误的行是:
featureDetector.detect(objectImage, objectKeyPoints);
我不知道错误是什么,因为错误没有详细说明。
我在Ubuntu上运行代码。
我得到的错误如下:
Java运行时环境检测到致命错误: SIGSEGV(0xb)at pc = 0x00007f9b24f3d747,pid = 29767, TID = 0x00007f9b438b2700
JRE版本:OpenJDK运行时环境(8.0_121-b13)(构建 1.8.0_121-8u121-b13-0ubuntu1.16.04.2-b13)Java VM:OpenJDK 64位服务器VM(25.121-b13混合模式linux-amd64压缩oops) 有问题的框架:C [libopencv_features2d.so.2.4 + 0x59747] cv :: FeatureDetector :: detect(cv :: Mat const&,std :: vector>&,cv :: Mat const&)const + 0x4d7
无法编写核心转储。核心转储已被禁用。启用 核心倾销,尝试" ulimit -c unlimited"再次启动Java之前
包含更多信息的错误报告文件保存为: /home/chandansr/MajorProjectParts/MajorProjectPart1/MotionDetection/hs_err_pid29767.log
如果您想提交错误报告,请访问:
http://bugreport.java.com/bugreport/crash.jsp事故发生了 在本机代码中的Java虚拟机之外。看有问题 报告错误的框架。
public class SURFDetector {
static{
System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
}
public static void main(String[] args) {
String bookObject = "/home/chandansr/source2.png";
String bookScene = "/home/chandansr/temp3.png";
System.out.println("Started....");
System.out.println("Loading images...");
Mat objectImage = Highgui.imread(bookObject);
Mat sceneImage = Highgui.imread(bookScene);
MatOfKeyPoint objectKeyPoints = new MatOfKeyPoint();
FeatureDetector featureDetector = FeatureDetector.create(FeatureDetector.SURF);
System.out.println("Detecting key points...");
featureDetector.detect(objectImage, objectKeyPoints);
System.out.println("Detected key points...");
KeyPoint[] keypoints = objectKeyPoints.toArray();
System.out.println(keypoints);
MatOfKeyPoint objectDescriptors = new MatOfKeyPoint();
DescriptorExtractor descriptorExtractor = DescriptorExtractor.create(DescriptorExtractor.SURF);
System.out.println("Computing descriptors...");
descriptorExtractor.compute(objectImage, objectKeyPoints, objectDescriptors);
// Create the matrix for output image.
Mat outputImage = new Mat(objectImage.rows(), objectImage.cols(), Highgui.CV_LOAD_IMAGE_COLOR);
Scalar newKeypointColor = new Scalar(255, 0, 0);
System.out.println("Drawing key points on object image...");
Features2d.drawKeypoints(objectImage, objectKeyPoints, outputImage, newKeypointColor, 0);
// Match object image with the scene image
MatOfKeyPoint sceneKeyPoints = new MatOfKeyPoint();
MatOfKeyPoint sceneDescriptors = new MatOfKeyPoint();
System.out.println("Detecting key points in background image...");
featureDetector.detect(sceneImage, sceneKeyPoints);
System.out.println("Computing descriptors in background image...");
descriptorExtractor.compute(sceneImage, sceneKeyPoints, sceneDescriptors);
Mat matchoutput = new Mat(sceneImage.rows() * 2, sceneImage.cols() * 2, Highgui.CV_LOAD_IMAGE_COLOR);
Scalar matchestColor = new Scalar(0, 255, 0);
List<MatOfDMatch> matches = new LinkedList<MatOfDMatch>();
DescriptorMatcher descriptorMatcher = DescriptorMatcher.create(DescriptorMatcher.FLANNBASED);
System.out.println("Matching object and scene images...");
descriptorMatcher.knnMatch(objectDescriptors, sceneDescriptors, matches, 2);
System.out.println("Calculating good match list...");
LinkedList<DMatch> goodMatchesList = new LinkedList<DMatch>();
float nndrRatio = 0.7f;
for (int i = 0; i < matches.size(); i++) {
MatOfDMatch matofDMatch = matches.get(i);
DMatch[] dmatcharray = matofDMatch.toArray();
DMatch m1 = dmatcharray[0];
DMatch m2 = dmatcharray[1];
if (m1.distance <= m2.distance * nndrRatio) {
goodMatchesList.addLast(m1);
}
}
if (goodMatchesList.size() >= 7) {
System.out.println("Object Found!!!");
List<KeyPoint> objKeypointlist = objectKeyPoints.toList();
List<KeyPoint> scnKeypointlist = sceneKeyPoints.toList();
LinkedList<Point> objectPoints = new LinkedList<>();
LinkedList<Point> scenePoints = new LinkedList<>();
for (int i = 0; i < goodMatchesList.size(); i++) {
objectPoints.addLast(objKeypointlist.get(goodMatchesList.get(i).queryIdx).pt);
scenePoints.addLast(scnKeypointlist.get(goodMatchesList.get(i).trainIdx).pt);
}
MatOfPoint2f objMatOfPoint2f = new MatOfPoint2f();
objMatOfPoint2f.fromList(objectPoints);
MatOfPoint2f scnMatOfPoint2f = new MatOfPoint2f();
scnMatOfPoint2f.fromList(scenePoints);
Mat homography = Calib3d.findHomography(objMatOfPoint2f, scnMatOfPoint2f, Calib3d.RANSAC, 3);
Mat obj_corners = new Mat(4, 1, CvType.CV_32FC2);
Mat scene_corners = new Mat(4, 1, CvType.CV_32FC2);
obj_corners.put(0, 0, new double[]{0, 0});
obj_corners.put(1, 0, new double[]{objectImage.cols(), 0});
obj_corners.put(2, 0, new double[]{objectImage.cols(), objectImage.rows()});
obj_corners.put(3, 0, new double[]{0, objectImage.rows()});
System.out.println("Transforming object corners to scene corners...");
Core.perspectiveTransform(obj_corners, scene_corners, homography);
Mat img = Highgui.imread(bookScene, Highgui.CV_LOAD_IMAGE_COLOR);
Core.line(img, new Point(scene_corners.get(0, 0)), new Point(scene_corners.get(1, 0)), new Scalar(0, 255, 0), 4);
Core.line(img, new Point(scene_corners.get(1, 0)), new Point(scene_corners.get(2, 0)), new Scalar(0, 255, 0), 4);
Core.line(img, new Point(scene_corners.get(2, 0)), new Point(scene_corners.get(3, 0)), new Scalar(0, 255, 0), 4);
Core.line(img, new Point(scene_corners.get(3, 0)), new Point(scene_corners.get(0, 0)), new Scalar(0, 255, 0), 4);
System.out.println("Drawing matches image...");
MatOfDMatch goodMatches = new MatOfDMatch();
goodMatches.fromList(goodMatchesList);
Features2d.drawMatches(objectImage, objectKeyPoints, sceneImage, sceneKeyPoints, goodMatches, matchoutput, matchestColor, newKeypointColor, new MatOfByte(), 2);
Highgui.imwrite("output//outputImage.jpg", outputImage);
Highgui.imwrite("output//matchoutput.jpg", matchoutput);
Highgui.imwrite("output//img.jpg", img);
} else {
System.out.println("Object Not Found");
}
System.out.println("Ended....");
}
}