Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include "opencv2/highgui/highgui.hpp"
- #include "opencv2/imgproc/imgproc.hpp"
- using namespace cv;
- using namespace std;
- int returnBiggest(vector<vector<Point>> counters);
- int main(int argc, char** argv)
- {
- VideoCapture cap(0);
- if (!cap.isOpened()) { return -1; }
- namedWindow("frame", 1);
- Mat frame, newFrame;
- vector<vector<Point>> contours;
- vector<Vec4i> hierarchy;
- while (true)
- {
- cap >> frame;
- flip(frame, frame, 1);
- imshow("frame", frame);
- cvtColor(frame, newFrame, CV_RGB2HSV);
- inRange(newFrame, Scalar(40, 45, 90), Scalar(85, 100, 160), newFrame);
- findContours(newFrame, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_NONE, Point(0, 0));
- imshow("newFrame", newFrame);
- // contours.at(returnBiggest(contours));
- if (waitKey(30) == 'q') { break; }
- }
- return 0;
- }
- int returnBiggest(vector<vector<Point>> counters)
- {
- int largest_area = 0;
- int largest_contour_index = 0;
- int i = 0;
- for (i = 0; i < counters.size(); i++) // iterate through each contour.
- {
- double a = contourArea(counters[i], false); // Find the area of contour
- if (a > largest_area)
- {
- largest_area = a;
- largest_contour_index = i; //Store the index of largest contour
- }
- }
- return largest_contour_index;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement