Advertisement
Guest User

Untitled

a guest
May 1st, 2016
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.67 KB | None | 0 0
  1. #include <opencv2/opencv.hpp>
  2. using namespace std;
  3.  
  4. void faktorial(int InSize, uchar *DataIn, uchar *DataOut)
  5. {
  6. for (int i = 0, j = 0; i < InSize; i += 3, j++)
  7. {
  8. DataOut[j] = (DataIn[i] + DataIn[i + 1] + DataIn[i + 2]) / 3;
  9. }
  10.  
  11. }
  12.  
  13. int main()
  14. {
  15. char tbLEN[] = "Assassin.jpg";
  16.  
  17. IplImage* image;
  18. image = cvLoadImage(tbLEN, 1);
  19.  
  20. IplImage *image2 = cvCreateImage(cvSize(image->width, image->height), IPL_DEPTH_8U, 1);
  21.  
  22. int height1 = image->height;
  23. int width1 = image->width;
  24. int step = image->widthStep;
  25. int SizeIn = step*height1;
  26. int nChannels = image->nChannels;
  27. uchar* DatIn = (uchar*)image->imageData;
  28. uchar* DatOut = (uchar*)image2->imageData;
  29.  
  30. faktorial(SizeIn, DatIn, DatOut);
  31.  
  32. cvNamedWindow("Imagecolor");
  33. cvShowImage("Imagecolor", image);
  34.  
  35. cvNamedWindow("Gray");
  36. cvShowImage("Gray", image2);
  37. cvWaitKey(0);
  38. return 0;
  39. }
  40.  
  41. void faktorial(int InSize, uchar *DataIn, uchar *DataOut)
  42. {
  43. for(int i = 0, j = 0; i < InSize; i += 3, j++)
  44. {
  45. DataOut[j] = (DataIn[i] + DataIn[i + 1] + DataIn[i + 2]) / 3;
  46. }
  47.  
  48. }
  49.  
  50. int main()
  51. {
  52. Mat img = imread("Assassin.jpg", CV_LOAD_IMAGE_UNCHANGED);
  53. if (img.empty())
  54. {
  55. cout << "Error : Image cannot be loaded..!!" << endl;
  56. return -1;
  57. }
  58.  
  59. uchar* DataImg = img.data;
  60.  
  61. int Width = img.cols;
  62. int Height = img.rows;
  63. int Step = img.step;
  64. int SizeInImg = Step * Height;
  65. Mat img2(img.rows,img.cols, CV_8UC3);
  66. uchar* DataImg2 = img2.data;
  67. faktorial(SizeInImg, DataImg, DataImg2);
  68.  
  69.  
  70. namedWindow("MyWindow", CV_WINDOW_AUTOSIZE);
  71. imshow("MyWindow", img2);
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement