OpenCV - How to convert a cpp code in C
i'm not good in cpp and i need to have a c interface of this code:

    #include <cv.h>
    #include <highgui.h>
    
    #include <vector>
    
    
    int main(int argc, char* argv[])
    {
        cv::Mat img = cv::imread(argv[1]);
    
        // Convert RGB Mat to GRAY
        cv::Mat gray;
        cv::cvtColor(img, gray, CV_BGR2GRAY);
    
        // Store the set of points in the image before assembling the bounding box
        std::vector<cv::Point> points;
        cv::Mat_<uchar>::iterator it = gray.begin<uchar>();
        cv::Mat_<uchar>::iterator end = gray.end<uchar>();
        for (; it != end; ++it)
        {
            if (*it) points.push_back(it.pos());
        }
    
        // Compute minimal bounding box
        cv::RotatedRect box = cv::minAreaRect(cv::Mat(points));
    
    // Draw bounding box in the original image (debug purposes)
    //cv::Point2f vertices[4];
    //box.points(vertices);
    //for (int i = 0; i < 4; ++i)
    //{
            //cv::line(img, vertices[i], vertices[(i + 1) % 4], cv::Scalar(0, 255, 0), 1, CV_AA);
    //}
    //cv::imshow("box", img);
    //cv::imwrite("box.png", img);
    
        // Set Region of Interest to the area defined by the box
        cv::Rect roi;
        roi.x = box.center.x - (box.size.width / 2);
        roi.y = box.center.y - (box.size.height / 2);
        roi.width = box.size.width;
        roi.height = box.size.height;
    
        // Crop the original image to the defined ROI
        cv::Mat crop = img(roi);
        cv::imshow("crop", crop);
    
        cv::imwrite("cropped.png", crop);
        cvWaitKey(0);
    
        return 0;
    }

can someone help me to wrap it or convert it?
thanks!!
OpenCV - How to convert a cpp code in C
===

i'm not good in cpp and i need to have a c interface of this code:

    #include <cv.h>
    #include <highgui.h>
    
    #include <vector>
    
    
    int main(int argc, char* argv[])
    {
        cv::Mat img = cv::imread(argv[1]);
    
        // Convert RGB Mat to GRAY
        cv::Mat gray;
        cv::cvtColor(img, gray, CV_BGR2GRAY);
    
        // Store the set of points in the image before assembling the bounding box
        std::vector<cv::Point> points;
        cv::Mat_<uchar>::iterator it = gray.begin<uchar>();
        cv::Mat_<uchar>::iterator end = gray.end<uchar>();
        for (; it != end; ++it)
        {
            if (*it) points.push_back(it.pos());
        }
    
        // Compute minimal bounding box
        cv::RotatedRect box = cv::minAreaRect(cv::Mat(points));
    
    // Draw bounding box in the original image (debug purposes)
    //cv::Point2f vertices[4];
    //box.points(vertices);
    //for (int i = 0; i < 4; ++i)
    //{
            //cv::line(img, vertices[i], vertices[(i + 1) % 4], cv::Scalar(0, 255, 0), 1, CV_AA);
    //}
    //cv::imshow("box", img);
    //cv::imwrite("box.png", img);
    
        // Set Region of Interest to the area defined by the box
        cv::Rect roi;
        roi.x = box.center.x - (box.size.width / 2);
        roi.y = box.center.y - (box.size.height / 2);
        roi.width = box.size.width;
        roi.height = box.size.height;
    
        // Crop the original image to the defined ROI
        cv::Mat crop = img(roi);
        cv::imshow("crop", crop);
    
        cv::imwrite("cropped.png", crop);
        cvWaitKey(0);
    
        return 0;
    }

can someone help me to wrap it or convert it?
thanks!!