Advertisement
Guest User

Untitled

a guest
Oct 26th, 2016
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.44 KB | None | 0 0
  1. - (bool) someMethod:(UIImage *)image :(UIImage *)temp {
  2.  
  3. RNG rng(12345);
  4.  
  5. cv::Mat src_base, hsv_base;
  6. cv::Mat src_test1, hsv_test1;
  7.  
  8. src_base = [self cvMatWithImage:image];
  9. src_test1 = [self cvMatWithImage:temp];
  10.  
  11. int thresh=150;
  12. double ans=0, result=0;
  13.  
  14. Mat imageresult1, imageresult2;
  15.  
  16. cv::cvtColor(src_base, hsv_base, cv::COLOR_BGR2HSV);
  17. cv::cvtColor(src_test1, hsv_test1, cv::COLOR_BGR2HSV);
  18.  
  19. std::vector<std::vector<cv::Point>>contours1, contours2;
  20. std::vector<Vec4i>hierarchy1, hierarchy2;
  21.  
  22. Canny(hsv_base, imageresult1, thresh, thresh*2);
  23. Canny(hsv_test1, imageresult2, thresh, thresh*2);
  24.  
  25. findContours(imageresult1,contours1,hierarchy1,CV_RETR_TREE,CV_CHAIN_APPROX_SIMPLE,cvPoint(0,0));
  26. for(int i=0;i<contours1.size();i++)
  27. {
  28. //cout<<contours1[i]<<endl;
  29. Scalar color=Scalar(rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255));
  30. drawContours(imageresult1,contours1,i,color,1,8,hierarchy1,0,cv::Point());
  31. }
  32.  
  33. findContours(imageresult2,contours2,hierarchy2,CV_RETR_TREE,CV_CHAIN_APPROX_SIMPLE,cvPoint(0,0));
  34. for(int i=0;i<contours2.size();i++)
  35. {
  36. Scalar color=Scalar(rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255));
  37. drawContours(imageresult2,contours2,i,color,1,8,hierarchy2,0,cv::Point());
  38. }
  39.  
  40.  
  41. for(int i=0;i<contours1.size();i++)
  42. {
  43. ans = matchShapes(contours1[i],contours2[i],CV_CONTOURS_MATCH_I1,0);
  44. cout<<" "<<ans<<endl;
  45. }
  46.  
  47. std::cout<<"The answer is "<<ans<<endl;
  48.  
  49. if (ans<=20) {
  50. return true;
  51. }
  52.  
  53. return false;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement