Question
How do you draw a line onto videocapture in c++ (openCV) and track if a object passes through it. We have been given a school
How do you draw a line onto videocapture in c++ (openCV) and track if a object passes through it.
We have been given a school project for mechatronics and robotics (BENG) the project is a wheel truing system , we are onto the image processing and we are unsure how to track if the wheel is buckled. We have been told that we should insert a horizontal line, which will be used to distinguish between where the wheel's position is if it's buckled either side of the centre midpoint of the wheel. This will then be used to return the BGR intensity values at this point, for an (x,y) position of the maximum point of buckling that is to be returned to the user in the command prompt window and stored.
Our idea is that when the wheel is passing through the line , it will track and print out the x and y coordinates , it would be really helpful if you could show us how to track the line on the camera .
Here is the code we use to draw the line onto the video capture in c++
" line(frame, Point(0, frame.rows / 2), Point(frame.cols, frame.rows / 2), Scalar(0,255,0), 5); "
Code we have ;
#include "opencv2/opencv.hpp" #include "opencv2/highgui/highgui.hpp" #include "opencv2\core\core.hpp" #include "opencv2/imgproc/imgproc.hpp" #include
using namespace cv; using namespace std;
int main() { VideoCapture cap(0); // open the default camera
if (!cap.isOpened()) // check if we succeeded return -1;
Mat edges; namedWindow("edges", 1);
for (;;) {
Mat frame; cap >> frame; // get a new frame from camera
line(frame, Point(0, frame.rows / 2), Point(frame.cols, frame.rows / 2), Scalar(0,255,0), 5);
cvtColor(frame, frame, CV_BGR2GRAY);//sets video to grayscale GaussianBlur(frame, edges, Size(9, 11), 0, 0);//higher value lower the white lines show Canny(edges, edges, 0, 30, 3);
imshow("Edges", edges); imshow("frame", frame); (waitKey(33) >= 0); // Pause key
} return 0; }
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started