diff --git a/contour_detection b/contour_detection new file mode 100755 index 0000000..4b28a9f Binary files /dev/null and b/contour_detection differ diff --git a/contour_detection.cpp b/contour_detection.cpp new file mode 100644 index 0000000..acb5e99 --- /dev/null +++ b/contour_detection.cpp @@ -0,0 +1,37 @@ +#include +#include +#include +#include +int main() +{ + cv::VideoCapture camera(0); + if (!camera.isOpened()) + { + std::cerr << "[ERROR] Could not open the camera!" << std::endl; + return 1; + } + //cv::namedWindow("Webcam", cv::WINDOW_AUTOSIZE); + while(true) + { + cv::Mat frame; + camera >> frame; + cv::imshow("Webcam", frame); + cv::Mat frame_gray; + cv::cvtColor(frame, frame_gray, cv::COLOR_BGR2GRAY); + cv::imshow("gray", frame_gray); + cv::Mat frame_thresh; + threshold(frame_gray, frame_thresh, 150, 255, cv::THRESH_BINARY); + cv::imshow("thresh", frame_thresh); + std::vector> contours; +std::vector hierarchy; + findContours(frame_thresh, contours, hierarchy, cv::RETR_TREE, cv::CHAIN_APPROX_NONE); + cv::Mat frame_contours = frame.clone(); + drawContours(frame_contours, contours, -1, cv::Scalar(255, 0, 0), 2); + cv::imshow("contours", frame_contours); + if (cv::waitKey(30) >= 0){ + + break; + } + } + return 0; +} diff --git a/makefile b/makefile index 79ec614..e88a5f9 100644 --- a/makefile +++ b/makefile @@ -1,5 +1,8 @@ -all: hello_world - g++ hello_world.o -o hello_world -L/usr/lib/x86_64-linux-gnu -lopencv_core -lopencv_highgui -lopencv_imgproc +all: contour_detection + g++ contour_detection.o -o contour_detection -L/usr/lib/x86_64-linux-gnu -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_imgcodecs -lopencv_videoio + +contour_detection: contour_detection.cpp + g++ -c contour_detection.cpp -I/usr/include/opencv4/opencv2 -I/usr/include/opencv4 main: main.cpp g++ -c main.cpp -I/usr/include/opencv4