我试图获取附加图像中对象的坐标,但无法获取:
我也得到了图像的坐标。
Using the Probabilistic Hough Transform
Line spotted:
pt1: (124, 478)
Line spotted:
pt1: (638, 477)
Line spotted:
pt1: (490, 261)
Line spotted:
pt1: (559, 262)
Line spotted:
pt1: (492, 263)
Line spotted:
pt1: (557, 263)
Line spotted:
pt1: (36, 478)
Line spotted:
pt1: (215, 127)
Line spotted:
pt1: (254, 59)
Line spotted:
pt1: (216, 129)
Line spotted:
pt1: (215, 126)
Line spotted:
pt1: (253, 59)
Line spotted:
pt1: (493, 263)
Line spotted:
pt1: (215, 128)
Line spotted:
pt1: (493, 52)
Line spotted:
pt1: (189, 226)
Line spotted:
pt1: (493, 54)
Line spotted:
pt1: (276, 280)
Line spotted:
pt1: (493, 261)
Line spotted:
pt1: (317, 264)
Line spotted:
pt1: (300, 285)
Line spotted:
pt1: (165, 186)
但我无法预测这些坐标是哪些图像,而且我需要图像中存在的三角形、矩形和圆形的倾斜角。
下面是代码
public class HoughLines {
public static void main(String[] args) {
String fileName = args.length >= 1 ? args[0] : "C:\\Users\\LENOVO\\Pictures\\24.png"; // if no params provided, compute the defaut image
// args[1] ="probabilistic";
IplImage src = cvLoadImage(fileName, 0);
IplImage dst;
IplImage colorDst;
CvMemStorage storage = cvCreateMemStorage(0);
CvSeq lines = new CvSeq();
CanvasFrame source = new CanvasFrame("Source");
CanvasFrame hough = new CanvasFrame("Hough");
if (src == null) {
System.out.println("Couldn't load source image.");
return;
}
dst = cvCreateImage(cvGetSize(src), src.depth(), 1);
colorDst = cvCreateImage(cvGetSize(src), src.depth(), 3);
cvCanny(src, dst, 50, 200, 3);
cvCvtColor(dst, colorDst, CV_GRAY2BGR);
/*
* apply the probabilistic hough transform
* which returns for each line deteced two points ((x1, y1); (x2,y2))
* defining the detected segment
*/
if (true) {
System.out.println("Using the Probabilistic Hough Transform");
lines = cvHoughLines2(dst, storage, CV_HOUGH_PROBABILISTIC, 1, Math.PI / 180, 40, 50, 10);
for (int i = 0; i < lines.total(); i++) {
// from JavaCPP, the equivalent of the C code:
// CvPoint* line = (CvPoint*)cvGetSeqElem(lines,i);
// CvPoint first=line[0], second=line[1]
// is:
// CvPoint first=line.position(0), secon=line.position(1);
Pointer line = cvGetSeqElem(lines, i);
CvPoint pt1 = new CvPoint(line).position(0);
CvPoint pt2 = new CvPoint(line).position(1);
System.out.println("Line spotted: ");
System.out.println("\t pt1: " + pt1);
//System.out.println("\t pt2: " + pt2);
cvLine(colorDst, pt1, pt2, CV_RGB(255, 0, 0), 3, CV_AA, 0); // draw the segment on the image
}
}
source.showImage(src);
hough.showImage(colorDst);
source.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
hough.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}
}
我也在添加原始图像: