contours
This commit is contained in:
parent
4417e6753b
commit
eb9ef725b1
|
|
@ -0,0 +1,48 @@
|
||||||
|
#include <iostream>
|
||||||
|
#include <opencv2/opencv.hpp>
|
||||||
|
#include <opencv2/highgui/highgui.hpp>
|
||||||
|
|
||||||
|
|
||||||
|
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);//normal
|
||||||
|
//---------- grey
|
||||||
|
cv::Mat frame_gray;
|
||||||
|
cv::cvtColor(frame,frame_gray,cv::COLOR_BGR2GRAY);
|
||||||
|
//cv::imshow("gray",frame_gray);//grey
|
||||||
|
//----------- treshold
|
||||||
|
cv::Mat frame_thresh;
|
||||||
|
threshold(frame_gray, frame_thresh, 150, 255, cv::THRESH_BINARY);
|
||||||
|
//cv::imshow("thresh", frame_thresh);
|
||||||
|
//----------- contour
|
||||||
|
std::vector<std::vector<cv::Point>> contours;
|
||||||
|
std::vector<cv::Vec4i> 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(0, 255, 0), 2);
|
||||||
|
|
||||||
|
cv::imshow("contours", frame_contours);
|
||||||
|
|
||||||
|
|
||||||
|
if (cv::waitKey(30) >= 0)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Binary file not shown.
BIN
hello_world.o
BIN
hello_world.o
Binary file not shown.
9
makefile
9
makefile
|
|
@ -1,6 +1,8 @@
|
||||||
all: main arithmetic hello
|
all: main arithmetic hello contour
|
||||||
g++ main.o arithmetic.o -L/usr/lib/x86_64-linux-gnu -lopencv_core
|
g++ main.o arithmetic.o -L/usr/lib/x86_64-linux-gnu -lopencv_core
|
||||||
|
|
||||||
|
g++ contour_detection.o -o contour -L/usr/lib/x86_64-linux-gnu -lopencv_core -lopencv_highgui -lopencv_imgproc -lopencv_videoio -lopencv_imgcodecs
|
||||||
|
|
||||||
main: main.cpp
|
main: main.cpp
|
||||||
g++ -c main.cpp -I/usr/include/opencv4
|
g++ -c main.cpp -I/usr/include/opencv4
|
||||||
|
|
||||||
|
|
@ -10,6 +12,9 @@ arithmetic: arithmetic.cpp arithmetic.h
|
||||||
hello: hello_world.cpp
|
hello: hello_world.cpp
|
||||||
g++ -c hello_world.cpp -I/usr/include/opencv4
|
g++ -c hello_world.cpp -I/usr/include/opencv4
|
||||||
|
|
||||||
|
contour: contour_detection.cpp
|
||||||
|
g++ -c contour_detection.cpp -I/usr/include/opencv4
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm *.o
|
rm *.o
|
||||||
rm a.out
|
rm a.out
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue