Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int regionGrowing(Mat im, Point p0, Point& pbf, Point& pja) {
- int count = 0;
- Point* fifo = new Point[0x100000];
- int nextIn = 0;
- int nextOut = 0;
- pbf = p0;
- pja = p0;
- if (getGray(im, p0.x, p0.y) < 128)
- return 0;
- fifo[nextIn++] = p0;
- setGray(im, p0.x, p0.y, 100);
- while (nextIn > nextOut) {
- Point p = fifo[nextOut++];
- ++count;
- if (p.x > 0)
- if (getGray(im, p.x - 1, p.y) > 128)
- {
- fifo[nextIn++] = Point(p.x - 1, p.y);
- setGray(im, p.x - 1, p.y, 100);
- if (pbf.x > p.x - 1) pbf.x = p.x - 1;
- }
- if (p.x < im.cols - 1)
- if (getGray(im, p.x + 1, p.y) > 128)
- {
- fifo[nextIn++] = Point(p.x + 1, p.y);
- setGray(im, p.x + 1, p.y, 100);
- if (pja.x < p.x + 1) pja.x = p.x + 1;
- }
- if (p.y > 0)
- if (getGray(im, p.x, p.y - 1) > 128)
- {
- fifo[nextIn++] = Point(p.x, p.y - 1);
- setGray(im, p.x, p.y - 1, 100);
- if (pbf.y > p.y - 1) pbf.y = p.y - 1;
- }
- if (p.y < im.rows - 1)
- if (getGray(im, p.x, p.y + 1) > 128)
- {
- fifo[nextIn++] = Point(p.x, p.y + 1);
- setGray(im, p.x, p.y + 1, 100);
- if (pja.y < p.y + 1) pja.y = p.y + 1;
- }
- }
- delete[]fifo;
- return count;
- }
- void vidlab()
- {
- //VideoCapture cap("IMG_6969.AVI");
- VideoCapture cap("IMG_6909.MOV");
- if (!cap.isOpened()) {
- cout << "Error opening video stream or file" << endl;
- return;
- }
- Mat frame, bground, result;
- Mat grayframe, edgeframe, drawframe, blurframe, laplaceframe;
- // Capture frame-by-frame
- int i = 0;
- while (1)
- {
- cap >> frame;
- // If the frame is empty, break immediately
- if (frame.empty()) {
- break;
- }
- resize(frame, frame, Size(frame.cols / 10, frame.rows / 10));
- i++;
- if (i == 7)
- {
- //elmentjuk hatterkepkent a 7. framet
- bground = frame;
- imshow("bground", bground);
- }
- if (i > 13)
- {
- result = ((bground - frame) + (frame - bground));
- //imshow("Abszolut kulonbseg", result);
- Mat rgb[3], & r = rgb[0], & g = rgb[1], & b = rgb[2];
- split(result, rgb);
- //osszeadjuk a kepcsatornakat
- r = r + g;
- r = r + b;
- threshold(r, r, 170, 255, THRESH_BINARY);
- erode(r, r, getStructuringElement(MORPH_RECT, Size(5, 5)));
- //imshow("egy bináris képet, amelyiken a fehér képpontok jelzik azokat a helyeket a képen", r);
- Point pbf, pja;
- int nrRect = 0;
- int roiSize;
- Rect roi;
- for (int x = 0; x < r.cols; x++)
- {
- for (int y = 0; y < r.rows; y++)
- {
- if (getGray(r, x, y) > 128)
- {
- int res = regionGrowing(r, Point(x, y), pbf, pja);
- if (res > 500)
- {
- if (!nrRect || res > roiSize)
- {
- roi.x = pbf.x;
- roi.y = pbf.y;
- roi.width = pja.x - pbf.x + 1;
- roi.height = pja.y - pbf.y + 1;
- roiSize = res;
- }
- ++nrRect;
- }
- }
- }
- }
- if (nrRect > 0) {
- rectangle(frame, Point(roi.x, roi.y),
- Point(roi.x + roi.width, roi.y + roi.height),
- Scalar(0, 255, 255, 0), 2);
- }
- imshow("Kepfelismeres", frame);
- }
- waitKey(1);
- }
- cap.release();
- }
- void lab11()
- {
- VideoCapture cap("IMG_6909.MOV");
- if (!cap.isOpened()) {
- cout << "Error opening video stream or file" << endl;
- return;
- }
- Mat frame;
- // Capture frame-by-frame
- int lowTh = 45;
- int highTh = 90;
- float szamok[9] = { 0.1, 0.1, 0.1, 0.1, 0.2, 0.1, 0.1, 0.1, 0.1 };//homalyositas
- for (;;)
- {
- // wait for a new frame from camera and store it into 'frame'
- cap.read(frame);
- // check if we succeeded
- if (frame.empty()) {
- cerr << "ERROR! blank frame grabbed\n";
- break;
- }
- resize(frame, frame, Size(frame.cols / 10, frame.rows / 10));
- // show live and wait for a key with timeout long enough to show images
- Mat grayscale, imgBlurred, imgCanny, median, maszk, F2;
- F2 = frame.clone();
- cvtColor(frame, grayscale, COLOR_RGB2GRAY); //gray video
- GaussianBlur(grayscale, imgBlurred, Size(5, 5), 1.8); // Blur Effect
- blur(frame, median, Size(5, 5)); //medianblur
- Canny(imgBlurred, imgCanny, lowTh, highTh); //edge detection
- maszk = Mat(3, 3, CV_32FC1, szamok);
- filter2D(F2, F2, -1, maszk);
- Mat abs_dst, dst;
- int kernel_size = 3;
- int scale = 1;
- int delta = 0;
- int ddepth = CV_16S;
- Laplacian(grayscale, dst, ddepth, kernel_size, scale, delta, BORDER_DEFAULT);
- // converting back to CV_8U
- convertScaleAbs(dst, abs_dst);
- Mat hist_equalized_image, frame2;
- frame2 = frame.clone();
- cvtColor(frame, hist_equalized_image, COLOR_BGR2YCrCb);
- //Split the image into 3 channels; Y, Cr and Cb channels respectively and store it in a std::vector
- vector<Mat> vec_channels;
- split(hist_equalized_image, vec_channels);
- //Equalize the histogram of only the Y channel
- equalizeHist(vec_channels[0], vec_channels[0]);
- //Merge 3 channels in the vector to form the color image in YCrCB color space.
- merge(vec_channels, hist_equalized_image);
- //Convert the histogram equalized image from YCrCb to BGR color space again
- cvtColor(hist_equalized_image, hist_equalized_image, COLOR_YCrCb2BGR);
- //imshow("equalized", hist_equalized_image);
- Mat resized1, resized2, frame3;
- frame3 = frame.clone();
- resize(frame, resized1, Size(800, 600));
- resize(frame3, resized2, Size(100, 100));
- imshow("nagy", resized1);
- imshow("kicsi", resized2);
- imshow("FilterLaplace", abs_dst);
- imshow("MyVideo", grayscale);
- imshow("Live", frame);
- imshow("imgCanny", imgCanny);
- imshow("imgGauss", imgBlurred);
- imshow("MedianBlurr", median);
- imshow("Filter", F2);
- if (waitKey(5) >= 0)
- break;
- }
- // When everything done, release the video capture object
- cap.release();
- }
- int main() {
- //lab01_changed();
- //lab02();
- //lab03();
- //lab04();
- //
- //lab05_01();
- //lab05_021();
- //lab05_022();
- //
- //lab06_A();
- //lab06_B();
- //lab06_C();
- //lab06_D();
- //lab06_E();
- //lab07_1();
- //lab07_2();
- //lab08();
- //lab09();
- //Watershed();
- vidlab();
- lab11();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement