OpenCv学习--图像画框标记rectangle

 

int testrectangle()
{
    char *imageSrc = "woman.jpg";
    Mat matImage = imread(imageSrc, -1);
    IplImage *iplImage = cvLoadImage(imageSrc, -1);

    if (matImage.data == 0 || iplImage->imageData == 0)
    {
        cout << "图片加载失败" << endl;
        return -1;
    }

    cv::rectangle(matImage, cvPoint(0, 0), cvPoint(200, 200), Scalar(255, 0, 0), 2, 1, 0);
    //Rect(int a,int b,int c,int d)a,b为矩形的左上角坐标,c,d为矩形的长和宽
    cv::rectangle(matImage, Rect(20, 40, 200, 200), Scalar(0, 0, 255), 5, 1, 0);
    //cvRectangle(iplImage, cvPoint(20, 200), cvPoint(200, 300), Scalar(0, 255, 255), 1, 1, 0);

    imshow("matImage", matImage);
    //cvShowImage("IplImage", iplImage);
    waitKey();
    return 0;
}

posted on 2015-10-26 11:26  Maddock  阅读(4420)  评论(0编辑  收藏  举报

导航