我在IOS中使用打開的CV。我已經在圖像中顯示圖像中的紙張邊界,並且現在我必須拖動這些邊界線來調整裁剪框。我們如何調整邊界線以及如何在邊界內裁剪圖像?調整角落並裁剪圖像openCV
這是可能的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;
}
感謝所有
你是如何創建的網格?你願意分享一些示例代碼嗎?我有類似的問題,張貼在這裏:http://stackoverflow.com/questions/13269432/perspective-transform-crop-in-ios-with-opencv – mmackh
@Gryphon我很想知道這一點。你是如何創建網格的? – alandalusi
@Gryphon請看我的帖子http://stackoverflow.com/questions/13594391/ios-drawing-a-rectangle-on-an-imageview-and-adjusting-borders – alandalusi