UmerJamil
UmerJamil

Reputation: 7

How to draw different shapes on an image in openCV?

I am a beginner in OpenCV. I know C++ and Android Programming. I have decided to shift on OpenCV. In my project, Using OpenCV I am detecting a red color ball through camera and getting its coordinates. Using these coordinates, I want to draw the same line or shape on a separate white image. For example, if the use user moves ball to write the alphabet W in the air, and I have received all the coordinates of ball position, I want to draw W on the separate image. I am not asking for code, but little help and guidance.

Thanks in advance.

Upvotes: 0

Views: 726

Answers (1)

api55
api55

Reputation: 11420

If you have the coordinates it is easy. First create your cv::Mat and set it all white.

cv::Mat image;
image.setTo(cv::Scalar(255,255,255));

Then if you have the begin and the end coordinates you can draw a line using opencv line function.

cv::line(image, cv::Point(initial_coords.x, initial_coords.y), cv::Point(end_coords.x, end_coords.y), cv::Scalar(0,0,255));

Finally to do the w use puttext function

cv::putText(image, "text", cv::Point(coords.x, coords.y), cv::FONT_HERSHEY_SCRIPT_SIMPLEX, 2, Scalar::all(255), 3,8);

If you need to erase the window before adding new things use again the

image.setTo(cv::Scalar(255,255,255));

Upvotes: 1

Related Questions