Advertisement
Guest User

Untitled

a guest
Apr 24th, 2014
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 9.01 KB | None | 0 0
  1. #include<opencv2corecore.hpp>
  2. #include<opencv2highguihighgui.hpp>
  3. #include<opencv2imgprocimgproc.hpp>
  4. #include"SIFT.h"
  5. #include<iostream>
  6. #include<stdio.h>
  7. #include<conio.h>
  8. using namespace cv;
  9. using namespace std;
  10. int main()
  11. {
  12. cout << "hello";
  13. Mat image = imread("abc.jpg",0);
  14. cout << image.channels() << endl;
  15. SIFT controller(image);
  16. controller.DoSIFT();
  17. waitKey(100000);
  18.  
  19. }
  20.  
  21. #include<opencv2corecore.hpp>
  22. #include<opencv2highguihighgui.hpp>
  23. #include<opencv2imgprocimgproc.hpp>
  24.  
  25. #include<iostream>
  26.  
  27. using namespace cv;
  28. using namespace std;
  29.  
  30. class SIFT{
  31.  
  32. private:
  33. Mat image_orig;
  34. Mat Scale_spaces[4][6];
  35. Mat LOG_img[4][4];
  36. Mat Extrema[4][2];
  37. Mat image_temp;
  38. Mat middle, up, down;
  39.  
  40.  
  41. void BuildScaleSpace()
  42. {
  43.  
  44. cout << "in build space" <<endl;
  45. int i, j;
  46. //image should be in grey scale
  47. cout << endl<<image_temp.rows << image_temp.cols << endl;
  48. GaussianBlur(image_temp, image_temp, cv::Size(5, 5), 0.5);
  49. resize(image_temp, image_temp, Size(image_temp.cols * 2, image_temp.rows * 2), 0, 0, 1);
  50. cout << image_temp.rows << image_temp.cols << endl;
  51. Scale_spaces[0][0] =image_temp;
  52. cout << endl << image_temp.rows << image_temp.cols << endl;
  53. GaussianBlur(Scale_spaces[0][0], Scale_spaces[0][0], cv::Size(5, 5), 1);
  54. double int_sigma = sqrt(2) / 2;
  55. double sigma = int_sigma;;
  56. double mid;
  57. double power = 1.0;
  58. for (i = 0; i < 4; i++)
  59. {
  60.  
  61. if (i>0)
  62. {
  63. sigma = mid;
  64. Scale_spaces[i][0] = image_temp;
  65. resize(image_temp, Scale_spaces[i][0], Size(image_temp.cols / power, image_temp.rows / power), 0, 0, 1);
  66. cout << endl << "after resizing" << Scale_spaces[i][0].rows << Scale_spaces[i][0].cols << endl;
  67. }
  68.  
  69. for (j = 1; j <= 5; j++)
  70. {
  71. if (j == 2)
  72. mid = sigma;
  73. // printf(" %f ", sigma);
  74. GaussianBlur(Scale_spaces[i][j-1], Scale_spaces[i][j], cv::Size(5, 5), sigma);
  75. sigma = sigma*sqrt(2);
  76.  
  77. }
  78. // printf("n");
  79. power = power * 2;
  80. }
  81.  
  82.  
  83.  
  84.  
  85. }
  86.  
  87. void ShowScaleSpace()
  88. {
  89. cout << "n show scalenn";
  90. namedWindow("image", CV_WINDOW_AUTOSIZE);
  91. int i, j;
  92. for (i = 0; i < 4; i++)
  93. {
  94. for (j = 0; j <= 5; j++)
  95. {
  96. cout << i<<" "<<j<<endl;
  97. cout << Scale_spaces[i][j].rows<<" " << Scale_spaces[i][j].cols << endl;
  98. imshow("image", Scale_spaces[i][j]);
  99. cvWaitKey(700);
  100. }
  101. }
  102.  
  103. }
  104.  
  105. void FindLOG()
  106. {
  107. cout << endl << "IN LOG " << endl;
  108. int i;
  109. int j;
  110. for (i = 0; i < 4; i++)
  111. {
  112. for (j = 1; j < 5; j++)
  113. {
  114. addWeighted(Scale_spaces[i][j], 1, Scale_spaces[i][j + 1], -1,0, LOG_img[i][j - 1]);
  115. }
  116. }
  117.  
  118. }
  119.  
  120. void FindMaxMin()
  121. {
  122.  
  123. cout << endl << "IN findmaxmin " << endl;
  124. int i;
  125. int j;
  126. int xiter, yiter;
  127. for (i = 0; i < 4; i++)
  128. {
  129. for (j = 1; j < 3; j++)
  130. {
  131.  
  132. std::cout << LOG_img[i][j].channels();
  133. middle = LOG_img[i][j].clone();
  134. up = LOG_img[i][j - 1].clone();
  135. down = LOG_img[i][j + 1].clone();
  136.  
  137. for (yiter = 1; yiter < middle.rows-1; yiter++)
  138. {
  139. for (xiter = 1; xiter < middle.cols-1; xiter++)
  140. {
  141. cout << i << " " << j << " " << yiter << " " << xiter<< " "<<endl;
  142. double currentPixel = middle.at<uchar>(yiter, xiter);
  143. cout << "1 ";
  144. // Check for a maximum
  145. if (cout << "helllo 2hhukjhgkj"&&currentPixel> middle.at<uchar>(yiter, xiter + 1) &&
  146. currentPixel> middle.at<uchar>(yiter, xiter - 1) &&
  147. currentPixel > middle.at<uchar>(yiter + 1, xiter) &&
  148. currentPixel > middle.at<uchar>(yiter + 1, xiter - 1) &&
  149. currentPixel > middle.at<uchar>(yiter, xiter + 1) &&
  150. currentPixel > middle.at<uchar>(yiter - 1, xiter) &&
  151. currentPixel > middle.at<uchar>(yiter - 1, xiter + 1) &&
  152. currentPixel > middle.at<uchar>(yiter - 1, xiter - 1) &&
  153.  
  154. currentPixel > up.at<uchar>(yiter, xiter) &&
  155. currentPixel > up.at<uchar>(yiter, xiter + 1) &&
  156. currentPixel > up.at<uchar>(yiter, xiter - 1) &&
  157. currentPixel > up.at<uchar>(yiter + 1, xiter) &&
  158. currentPixel > up.at<uchar>(yiter + 1, xiter - 1) &&
  159. currentPixel > up.at<uchar>(yiter, xiter + 1) &&
  160. currentPixel > up.at<uchar>(yiter - 1, xiter) &&
  161. currentPixel > up.at<uchar>(yiter - 1, xiter + 1) &&
  162. currentPixel > up.at<uchar>(yiter - 1, xiter - 1) &&
  163.  
  164. currentPixel > down.at<uchar>(yiter, xiter) &&
  165. currentPixel > down.at<uchar>(yiter, xiter + 1) &&
  166. currentPixel > down.at<uchar>(yiter, xiter - 1) &&
  167. currentPixel > down.at<uchar>(yiter + 1, xiter) &&
  168. currentPixel > down.at<uchar>(yiter + 1, xiter - 1) &&
  169. currentPixel > down.at<uchar>(yiter, xiter + 1) &&
  170. currentPixel > down.at<uchar>(yiter - 1, xiter) &&
  171. currentPixel > down.at<uchar>(yiter - 1, xiter + 1) &&
  172. currentPixel > down.at<uchar>(yiter - 1, xiter - 1)
  173. )
  174. {
  175. cout << "inside, updating extrema ";
  176. Extrema[i][j - 1].at<uchar>(xiter, yiter) = 255;
  177. }
  178.  
  179. else if (currentPixel< middle.at<uchar>(yiter, xiter + 1) &&
  180. currentPixel< middle.at<uchar>(yiter, xiter - 1) &&
  181. currentPixel < middle.at<uchar>(yiter + 1, xiter) &&
  182. currentPixel < middle.at<uchar>(yiter + 1, xiter - 1) &&
  183. currentPixel < middle.at<uchar>(yiter, xiter + 1) &&
  184. currentPixel < middle.at<uchar>(yiter - 1, xiter) &&
  185. currentPixel < middle.at<uchar>(yiter - 1, xiter + 1) &&
  186. currentPixel < middle.at<uchar>(yiter - 1, xiter - 1) &&
  187.  
  188. currentPixel < up.at<uchar>(yiter, xiter) &&
  189. currentPixel < up.at<uchar>(yiter, xiter + 1) &&
  190. currentPixel < up.at<uchar>(yiter, xiter - 1) &&
  191. currentPixel < up.at<uchar>(yiter + 1, xiter) &&
  192. currentPixel < up.at<uchar>(yiter + 1, xiter - 1) &&
  193. currentPixel < up.at<uchar>(yiter, xiter + 1) &&
  194. currentPixel < up.at<uchar>(yiter - 1, xiter) &&
  195. currentPixel < up.at<uchar>(yiter - 1, xiter + 1) &&
  196. currentPixel < up.at<uchar>(yiter - 1, xiter - 1) &&
  197.  
  198. currentPixel < down.at<uchar>(yiter, xiter) &&
  199. currentPixel < down.at<uchar>(yiter, xiter + 1) &&
  200. currentPixel < down.at<uchar>(yiter, xiter - 1) &&
  201. currentPixel < down.at<uchar>(yiter + 1, xiter) &&
  202. currentPixel < down.at<uchar>(yiter + 1, xiter - 1) &&
  203. currentPixel < down.at<uchar>(yiter, xiter + 1) &&
  204. currentPixel < down.at<uchar>(yiter - 1, xiter) &&
  205. currentPixel < down.at<uchar>(yiter - 1, xiter + 1) &&
  206. currentPixel < down.at<uchar>(yiter - 1, xiter - 1)
  207. )
  208. {
  209. Extrema[i][j - 1].at<uchar>(xiter, yiter) = 255;
  210. }
  211.  
  212. else
  213. Extrema[i][j - 1].at<uchar>(xiter, yiter) = 0;
  214. }
  215.  
  216.  
  217.  
  218.  
  219. }
  220. }
  221. }
  222. }
  223.  
  224.  
  225.  
  226. public:
  227. SIFT(Mat Image)
  228. {
  229. image_orig = Image;
  230. image_temp = Image;
  231.  
  232. }
  233.  
  234. void DoSIFT()
  235. {
  236.  
  237. BuildScaleSpace();
  238. //ShowScaleSpace();
  239. FindLOG();
  240. FindMaxMin();
  241.  
  242.  
  243. }
  244.  
  245.  
  246.  
  247. };
  248.  
  249. currentPixel> middle.at<uchar>(yiter, xiter + 1)
  250.  
  251. Extrema[i][j - 1].at<uchar>(xiter, yiter) = ??? ;
  252.  
  253. if( Extrema[i][j - 1].empty() == true )
  254. cerr << "Fatal error" << endl ;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement