【发布时间】:2012-10-17 09:03:00
【问题描述】:
我在 IOS 中使用开放式简历。我已经在图像中检测到纸张的边界,如图所示,现在我必须在触摸时拖动这些边界线以调整裁剪框。我们如何调整边界线以及如何在边界内裁剪图像?
这在 openCV 中是可能的,还是我为此使用 openGL?
@moosgummi : 我在下面的方法中调用你的方法
- (cv::Mat)finshWork:(cv::Mat &)image
{
Mat img0 =image;
Mat img1;
cvtColor(img0, img1, CV_RGB2GRAY);
// apply your filter
Canny(img1, img1, 100, 200);
// find the contours
vector< vector<cv::Point> > contours;
findContours(img1, contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE);
// you could also reuse img1 here
Mat mask = Mat::zeros(img1.rows, img1.cols, CV_8UC1);
// CV_FILLED fills the connected components found
drawContours(mask, contours, -1, Scalar(255), CV_FILLED);
// let's create a new image now
Mat crop(img0.rows, img0.cols, CV_8UC3);
// set background to green
crop.setTo(Scalar(0,255,0));
// and copy the magic apple
img0.copyTo(crop, mask);
// normalize so imwrite(...)/imshow(...) shows the mask correctly!
normalize(mask.clone(), mask, 0.0, 255.0, CV_MINMAX, CV_8UC1);
std::vector<cv::Point> biggestContour = contours[contours.size()-1];
NSLog(@"%d",biggestContour[0].x);
NSLog(@"%d",biggestContour[0].y);
cv::Mat paperImage =[self getPaperAreaFromImage:image:biggestContour];
//return crop;
return paperImage;
}
谢谢大家
【问题讨论】:
-
您是如何创建网格的?你愿意分享一些示例代码吗?我有类似的问题,发在这里:stackoverflow.com/questions/13269432/…
-
@Gryphon 我也很想知道这一点。您是如何创建网格的?
-
@Gryphon 请看我的帖子stackoverflow.com/questions/13594391/…
-
@alandalusi 这是天才扫描的示例图像,我正在通过 openCV 检测角落。
-
@Gryphon 啊哈.. 明白了。所以现在我们有同样的追求。顺便说一句,上面的代码是否可以很好地检测边界?
标签: iphone objective-c ios image-processing opencv