Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- - (bool) someMethod:(UIImage *)image :(UIImage *)temp {
- RNG rng(12345);
- cv::Mat src_base, hsv_base;
- cv::Mat src_test1, hsv_test1;
- src_base = [self cvMatWithImage:image];
- src_test1 = [self cvMatWithImage:temp];
- int thresh=150;
- double ans=0, result=0;
- Mat imageresult1, imageresult2;
- cv::cvtColor(src_base, hsv_base, cv::COLOR_BGR2HSV);
- cv::cvtColor(src_test1, hsv_test1, cv::COLOR_BGR2HSV);
- std::vector<std::vector<cv::Point>>contours1, contours2;
- std::vector<Vec4i>hierarchy1, hierarchy2;
- Canny(hsv_base, imageresult1, thresh, thresh*2);
- Canny(hsv_test1, imageresult2, thresh, thresh*2);
- findContours(imageresult1,contours1,hierarchy1,CV_RETR_TREE,CV_CHAIN_APPROX_SIMPLE,cvPoint(0,0));
- for(int i=0;i<contours1.size();i++)
- {
- //cout<<contours1[i]<<endl;
- Scalar color=Scalar(rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255));
- drawContours(imageresult1,contours1,i,color,1,8,hierarchy1,0,cv::Point());
- }
- findContours(imageresult2,contours2,hierarchy2,CV_RETR_TREE,CV_CHAIN_APPROX_SIMPLE,cvPoint(0,0));
- for(int i=0;i<contours2.size();i++)
- {
- Scalar color=Scalar(rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255));
- drawContours(imageresult2,contours2,i,color,1,8,hierarchy2,0,cv::Point());
- }
- for(int i=0;i<contours1.size();i++)
- {
- ans = matchShapes(contours1[i],contours2[i],CV_CONTOURS_MATCH_I1,0);
- cout<<" "<<ans<<endl;
- }
- std::cout<<"The answer is "<<ans<<endl;
- if (ans<=20) {
- return true;
- }
- return false;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement