draw rectangle opencv c++

Sure, here is a response:

To draw a rectangle in OpenCV using C++, you can follow these steps:

  1. Include the necessary OpenCV library at the beginning of your code:
#include <opencv2/opencv.hpp>
  1. Create a window to display the rectangle:
cv::Mat image = cv::Mat::zeros(300, 300, CV_8UC3);
cv::namedWindow("Rectangle", cv::WINDOW_AUTOSIZE);
  1. Define the rectangle parameters (top-left corner and bottom-right corner):
cv::Point topLeft(50, 50);
cv::Point bottomRight(200, 200);
  1. Draw the rectangle on the image:
cv::rectangle(image, topLeft, bottomRight, cv::Scalar(0, 255, 0), 2);
  1. Display the image with the rectangle:
cv::imshow("Rectangle", image);
  1. Wait for a key press and then close the window:
cv::waitKey(0);
cv::destroyWindow("Rectangle");