我正在尝试使用 JavaCV 识别停车场
我有这样的图像(带角度):
我希望该软件能够识别这些地方并脱颖而出,获得坐标,就像这样(抱歉,Photoshop 不好):
到目前为止我的代码:
imgOriginal = cvLoadImage("D:\\imagem\\original2.JPG");
imgModify = cvCreateImage(cvGetSize(imgOriginal), IPL_DEPTH_8U, 1);
imgOut = cvCloneImage(imgOriginal);
cvSmooth(imgOut, imgOut, CV_GAUSSIAN, 3);
cvCvtColor(imgOut, imgModify, CV_BGR2GRAY);
cvThreshold(imgModify, imgModify, 0, 255, CV_THRESH_BINARY + CV_THRESH_OTSU);
cvErode(imgModify, imgModify, null, 1);
CvMemStorage storage = cvCreateMemStorage(0);
CvSeq cvSeq = cvCreateSeq(0, Loader.sizeof(CvContour.class), Loader.sizeof(CvSeq.class), storage);
cvFindContours(imgModificada, storage, cvSeq, Loader.sizeof(CvContour.class), CV_RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE);
int objects = 0;
CvRect region;
for (; cvSeq != null; cvSeq = cvSeq.h_next()) {
double areaObject = Math.abs(cvContourArea(cvSeq, CV_WHOLE_SEQ, 0));
if (areaObject > 500) { //ignore small contours
objects++;
region = cvBoundingRect(cvSeq, 0);
cvRectangle(imgOut, cvPoint(region.x(), region.y()), cvPoint(region.x() + region.width(), region.y() + region.height()), CvScalar.BLUE, 1, CV_AA, 0);
}
}
System.out.println(objects);
cvShowImage("Out", imgOut);
cvWaitKey(0);
cvReleaseImage(imgOut);
我该如何做输出图像?有谁知道?谢谢。