Guest User

Untitled

a guest
May 22nd, 2018
90
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.81 KB | None | 0 0
  1. // assignment3.cpp : Defines the entry point for the console application.
  2. //
  3. #include "stdafx.h"
  4. #include <stdlib.h>
  5. #include <stdio.h>
  6. #include <iostream>
  7. #include <cv.h>
  8. #include <cxcore.h>
  9. #include <highgui.h>
  10. #include <conio.h>
  11. #include <cxtypes.h>
  12. #include <math.h>
  13. #include <iostream>
  14. #include <algorithm>
  15. #include <fstream>
  16. #include <string>
  17. #include <sstream>
  18. using namespace std;
  19. void my_mouse_callback( int event, int x, int y, int flags, void* param );
  20.  
  21. CvRect box;
  22. int press=0;
  23. int x1;
  24. int y11;
  25. int x2;
  26. int y2;
  27. int x3;
  28. int y3;
  29. int x4;
  30. int y4;
  31. IplImage* X;
  32. IplImage* Y;
  33. IplImage* Z;
  34. IplImage* test1;
  35. IplImage* test2;
  36. IplImage* test3;
  37.  
  38.  
  39. //IplImage* D1;
  40.  
  41. //bool drawing_box = false;
  42. void LoadMyImage2()
  43. {
  44. //Load Image
  45. X = cvLoadImage("vodafone.png",0);
  46. Y = cvLoadImage("mobinile.png",0);
  47. Z = cvLoadImage("mobinila.png",0);
  48. //>0 the loaded image is forced to be a 3-channel color image
  49. //=0 the loaded image is forced to be a 1 channel grayscale image
  50. //<0 the loaded image is loaded as is (with number of channels in the file).
  51. //cvFindHomography cvWarpPerspective
  52. //CvMat* matrix=cvCreateMat(4,2,Cv32F
  53. }
  54.  
  55. void showPicture2(IplImage* i, char* title)
  56. {
  57. //Create a Window
  58. cvNamedWindow(title,CV_WINDOW_AUTOSIZE);
  59. int mouseParam = 5;
  60. cvSetMouseCallback( title, my_mouse_callback,&mouseParam);
  61. //Display Image in Window
  62. cvShowImage(title, i);
  63. cvWaitKey();
  64. }
  65.  
  66. IplImage* ezbotha(int x1,int y1,int x2,int y2, int x3,int y3,int x4 ,int y4,IplImage* src) {
  67. IplImage* dest=cvCloneImage(src);
  68. double xysrc[8] = {x1, x2, x3, x4,
  69. y1, y2, y3, y4};
  70. CvMat matrix1 = cvMat(2,4, CV_64F, xysrc);
  71. double xydst[8] = {x1, x2, x1, x2,
  72. y1, y1, y3, y3};
  73. CvMat matrix2 = cvMat(2,4, CV_64F, xydst);
  74. double heyheyhey[9];
  75. CvMat Homography= cvMat(3,3, CV_64F, heyheyhey);
  76. cvFindHomography(&matrix1,&matrix2,&Homography);
  77. cvWarpPerspective(src,dest,&Homography);
  78. return dest;
  79. }
  80. IplImage* threshold (IplImage* img){
  81. IplImage* copy=cvCloneImage(img);
  82. static uchar *created = (uchar *)copy->imageData;
  83.  
  84. int height=copy->height;
  85. int width=copy->width;
  86. int channels= copy->nChannels;
  87. //now to color
  88. for(int i=0;i<height;i++) for(int j=0;j<width;j++) for(int k=0;k<channels;k++)
  89. {
  90. if(created[i*copy->widthStep +(j*copy->nChannels+k)] < 170 )
  91. {
  92. created[i*img->widthStep+(j*copy->nChannels+k)] = 255 ;
  93.  
  94. }
  95. else
  96. {
  97. created[i*copy->widthStep+(j*copy->nChannels+k)] = 0 ; //Saturation
  98. }
  99.  
  100. }
  101. return copy;
  102.  
  103. }
  104. void my_mouse_callback( int event, int x, int y, int flags, void* param ){
  105. IplImage* image = (IplImage*) param;
  106.  
  107. switch( event ){
  108.  
  109. case CV_EVENT_LBUTTONDOWN:
  110. if (press==0){
  111. x1=x;
  112. y11=y;
  113. }
  114. else if (press==1){
  115. x2=x;
  116. y2=y;
  117. }
  118. else if (press==2){
  119. x3=x;
  120. y3=y;
  121. }
  122. else if (press==3){
  123. x4=x;
  124. y4=y;
  125.  
  126. press =10;
  127.  
  128. }
  129. press++;
  130. break;
  131. }}
  132.  
  133. int _tmain(int argc, _TCHAR* argv[])
  134. {
  135. //When using the console you will have to try to make it user friendly
  136. //Use prints to explain to the user how to use your application
  137. //Take inputs from the user in form of commands to use your application
  138.  
  139. LoadMyImage2();
  140. test1=cvLoadImage("IMG_0119.png",0);
  141. showPicture2(test1,"hussien");
  142. cout<<x1<<" "<<y11<<endl;
  143. cout<<x2<<" "<<y2<<endl;
  144. cout<<x3<<" "<<y3<<endl;
  145. cout<<x4<<" "<<y4<<endl;
  146. test2=ezbotha(x1,y11,x2,y2,x3,y3,x4,y4,test1);
  147. showPicture2(test2,"hussieeen");
  148. test3=threshold(test2);
  149. showPicture2(test3,"hussieeen");
  150.  
  151. IplImage* distTransformImage = cvCreateImage(cvSize(test3->width, test3->height), test3->depth, test3->nChannels);
  152. cvDistTransform(test3, distTransformImage, CV_DIST_L1, CV_DIST_MASK_3, 0);
  153. showPicture2(distTransformImage,"man");
  154.  
  155.  
  156. //showPicture(A,"hussien");
  157. getch();
  158.  
  159. return 1;
  160. return 0;
  161. }
Add Comment
Please, Sign In to add comment