Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <opencv2/highgui/highgui.hpp>
- #include <opencv2/imgproc/imgproc.hpp>
- #include "opencv2/opencv.hpp"
- using namespace cv;
- using namespace std;
- void filtracja_sobela(Mat & obrazek)
- {
- Mat Sx,Sy;
- Sx=(Mat_<double>(3,3) << -1,0,1,-2,0,2,-1,0,1);
- Sy=(Mat_<double>(3,3) << -1,-2,-1,0,0,0,1,2,1);
- Mat sxo,syo;
- filter2D(obrazek,sxo,-1,Sx,Point(-1,-1),0,BORDER_DEFAULT);
- filter2D(obrazek,syo,-1,Sy,Point(-1,-1),0,BORDER_DEFAULT);
- sxo*=(double)0.25;
- syo*=(double)0.25;
- cv::pow(sxo,2,sxo);
- cv::pow(syo,2,syo);
- addWeighted(sxo,1,syo,1,0,obrazek,-1);
- cv::sqrt(obrazek,obrazek);
- }
- void filtracja_cannyiego(Mat & obrazek,double thresh_val)
- {
- Mat obrazek2;
- filtracja_sobela(obrazek);
- threshold(obrazek,obrazek2,thresh_val,255,THRESH_BINARY);
- for(int i;i<obrazek.cols;i++)
- {
- for(int j;j<obrazek.rows;j++)
- {
- if(obrazek2.col(i).row(j)=255)
- {
- 1;
- }
- }
- }
- }
- inline void test_mnozenie(void)
- {
- Mat test,test2;
- test=(Mat_<double>(3,3) << 2,2,2,2,2,2,2,2,2);
- test2=(Mat_<double>(3,3) << 1,2,3,4,5,6,7,8,9);
- test.mul(test2,1);//to sie nie nadaje do mnozenia przez skalar
- test=test*4;//prosto i przyjenie
- cout<<test<<endl;
- //maly tescik potegowania
- cv::pow(test,2,test);
- cout<<test;
- //tescik wyboru podmacierzy
- cout << endl;
- Mat mat1, mat2;
- mat1.create(Size(5, 5), CV_8UC1);
- randu(mat1, Scalar::all(0), Scalar::all(10));
- Mat mat3(mat1, Rect(2, 2, 2, 2));
- mat2 = mat1;
- cout << mat1 << endl << mat2 << endl << mat3 << endl;
- mat2.setTo(6);
- cout << mat1 << endl << mat2 << endl << mat3 << endl;
- }
- int main(int, char**)
- {
- test_mnozenie();
- Mat picture1,picture2;
- picture1=imread("/home/tomek/Documents/polecenia_opencv/japko3.jpg",CV_LOAD_IMAGE_COLOR);
- cvtColor(picture1,picture1,CV_RGB2GRAY);
- picture1.convertTo(picture1,CV_32F);
- // /////////////
- //filtracja_sobela(picture1);
- filtracja_cannyiego(picture1,30);
- //*************************
- Mat cur_image;
- picture1.copyTo(cur_image);
- cur_image.convertTo(cur_image,CV_8U);
- namedWindow("image");
- int lowerb = 0, upperb = 109; //Ustalenie wartosci poczatkowych trackbarow
- createTrackbar( "lb", "image", &lowerb, 255, NULL );
- //Utworzenie trackbar'ow
- createTrackbar( "ub", "image", &upperb, 255, NULL );
- cur_image+=lowerb;
- for (;;)
- {
- imshow("image", cur_image);
- if (waitKey(30) >= 0) break;
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement