Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void CallBackL4(int event, int x, int y, int flags, void *userdata)
- {
- Mat* H = (Mat*)userdata;
- if (event == EVENT_RBUTTONDOWN)
- {
- imshow("H", *H);
- int width = (*H).cols;
- int height = (*H).rows;
- Mat labels = Mat::zeros((*H).size(),CV_16UC1);
- Mat dst = Mat::zeros((*H).size(), CV_8UC1);
- queue<Point> que;
- double hue_avg = (*H).at<uchar>(y, x);
- printf("salut");
- int k = 1; //ethiceta curenta
- int N = 1; // numarul de pixeli din regiune
- que.push(Point(y, x)); // adauga element (seed point) in coada
- // acesta primeste eticheta k
- while (!que.empty())
- { // Retine poz. celui mai vechi element din coada
- Point oldest = que.front();
- que.pop(); // scoate element din coada
- int xx = oldest.y; // coordonatele lui
- int yy = oldest.x;
- // Pentru fiecare vecin al pixelului (xx, yy)
- // Daca abs(hue(vecin) – Hue_avg)<T si labels(vecin) == 0
- // Aduga vecin la regiunea curenta
- // labels(vecin) = k
- // Actualizeaza Hue_avg (medie ponderata)
- // Incrementeza N
- for (int v = -1; v <= 1; v++)
- for (int u = -1; u <= 1; u++)
- {
- if (yy <= height - 1 && xx <= width - 1){
- if (abs((*H).at<uchar>(yy + v, xx +
- u) - hue_avg) < 55 && labels.at<uchar>(yy + v, xx + u) == 0){
- que.push(Point(yy + v, xx +
- u));
- labels.at<uchar>(yy + v, xx
- + u) = k;
- hue_avg = (N * hue_avg +
- (*H).at<uchar>(yy + v, xx + u)) / (N + 1);
- N++;
- }
- }
- }
- }
- for (int i = 0; i < height;i++)
- for (int j = 0; j < width; j++)
- {
- if (labels.at<uchar>(i,j) != 0) {
- dst.at<uchar>(i, j) = 255;
- }
- }
- imshow("dst", dst);
- }
- }
- void L4_RG()
- {
- Mat src;
- Mat channels[3],hsv,H;
- // Read image from file
- char fname[MAX_PATH];
- while (openFileDlg(fname))
- {
- src = imread(fname);
- GaussianBlur(src, src, Size(5, 5), 0, 0);//filtru Gausian
- cvtColor(src, hsv, CV_BGR2HSV);//conversie bgr-> hsv
- split(hsv, channels);//separare hsv
- H = channels[0]*510/360;
- //Create a window
- namedWindow("src", 1);
- //set the callback function for any mouse event
- setMouseCallback("src", CallBackL4, &H);
- //show the image
- imshow("src", src);
- // Wait until user press some key
- waitKey(0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement