Advertisement
Guest User

Untitled

a guest
Nov 26th, 2014
160
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.57 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <opencv2/highgui/highgui.hpp>
  3. #include <opencv2/imgproc/imgproc.hpp>
  4.  
  5. #include "opencv2/opencv.hpp"
  6. using namespace cv;
  7. using namespace std;
  8.  
  9.  
  10.  
  11.  
  12. void filtracja_sobela(Mat & obrazek)
  13. {
  14.     Mat Sx,Sy;
  15.     Sx=(Mat_<double>(3,3) << -1,0,1,-2,0,2,-1,0,1);
  16.     Sy=(Mat_<double>(3,3) << -1,-2,-1,0,0,0,1,2,1);
  17.  
  18.     Mat sxo,syo;
  19.     filter2D(obrazek,sxo,-1,Sx,Point(-1,-1),0,BORDER_DEFAULT);
  20.     filter2D(obrazek,syo,-1,Sy,Point(-1,-1),0,BORDER_DEFAULT);
  21.  
  22.     sxo*=(double)0.25;
  23.     syo*=(double)0.25;
  24.  
  25.     cv::pow(sxo,2,sxo);
  26.     cv::pow(syo,2,syo);
  27.  
  28.     addWeighted(sxo,1,syo,1,0,obrazek,-1);
  29.     cv::sqrt(obrazek,obrazek);
  30.  
  31. }
  32.  
  33.  
  34. void filtracja_cannyiego(Mat & obrazek,double thresh_val)
  35. {
  36.     Mat obrazek2;
  37.     filtracja_sobela(obrazek);
  38.  
  39.     threshold(obrazek,obrazek2,thresh_val,255,THRESH_BINARY);
  40.  
  41.     for(int i;i<obrazek.cols;i++)
  42.     {
  43.         for(int j;j<obrazek.rows;j++)
  44.         {
  45.             if(obrazek2.col(i).row(j)=255)
  46.             {
  47.                 1;
  48.             }
  49.         }
  50.     }
  51.  
  52. }
  53.  
  54. inline void test_mnozenie(void)
  55. {
  56.     Mat test,test2;
  57.     test=(Mat_<double>(3,3) << 2,2,2,2,2,2,2,2,2);
  58.     test2=(Mat_<double>(3,3) << 1,2,3,4,5,6,7,8,9);
  59.     test.mul(test2,1);//to sie nie nadaje do mnozenia przez skalar
  60.  
  61.     test=test*4;//prosto i przyjenie
  62.  
  63.     cout<<test<<endl;
  64.  
  65.     //maly tescik potegowania
  66.     cv::pow(test,2,test);
  67.     cout<<test;
  68.  
  69.     //tescik wyboru podmacierzy
  70.     cout << endl;
  71.     Mat mat1, mat2;
  72.     mat1.create(Size(5, 5), CV_8UC1);
  73.     randu(mat1, Scalar::all(0), Scalar::all(10));
  74.     Mat mat3(mat1, Rect(2, 2, 2, 2));
  75.     mat2 = mat1;
  76.     cout << mat1 << endl << mat2 << endl << mat3 << endl;
  77.     mat2.setTo(6);
  78.     cout << mat1 << endl << mat2 << endl << mat3 << endl;
  79. }
  80.  
  81. int main(int, char**)
  82. {
  83. test_mnozenie();
  84.  
  85.  
  86.  Mat picture1,picture2;
  87. picture1=imread("/home/tomek/Documents/polecenia_opencv/japko3.jpg",CV_LOAD_IMAGE_COLOR);
  88. cvtColor(picture1,picture1,CV_RGB2GRAY);
  89. picture1.convertTo(picture1,CV_32F);
  90. // /////////////
  91. //filtracja_sobela(picture1);
  92. filtracja_cannyiego(picture1,30);
  93.  
  94.  
  95.  
  96.  
  97. //*************************
  98. Mat cur_image;
  99.  
  100. picture1.copyTo(cur_image);
  101. cur_image.convertTo(cur_image,CV_8U);
  102.  
  103. namedWindow("image");
  104.  
  105. int lowerb = 0, upperb = 109;    //Ustalenie wartosci poczatkowych trackbarow
  106.     createTrackbar( "lb", "image", &lowerb, 255, NULL );
  107.     //Utworzenie trackbar'ow
  108.     createTrackbar( "ub", "image", &upperb, 255, NULL );
  109.  
  110. cur_image+=lowerb;
  111. for (;;)
  112. {
  113.  
  114.  
  115.  
  116.  
  117. imshow("image", cur_image);
  118. if (waitKey(30) >= 0) break;
  119. }
  120. return 0;
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement