opencv ROI

/*
this is the fundtion part of book <<learning opencv 1st>> 's code
Author:hujian in nankai 2016/4/5
i will give 2 styles code here and the c-style function 
will contain cv- and c++-style without cv-
*/
#include "utily.h"

//first of all,show the image
//c style function
//
void cvShowImage(char* filename)
{
    IplImage* image = cvLoadImage(filename);
    if (!image){
        printf("Can not open file.\n");
        exit(EXIT_FAILURE);
    }
    //show this image
    //
    cvNamedWindow("Image");
    cvShowImage("Image", image);
    if (cvWaitKey(10) >= 0)
    //release the resource
    //
    {
        cvReleaseImage(&image);
        cvDestroyWindow("Image");
    }
    return;
}
//first of all,show the image
//c++ style function
//
void ShowImage(char* filename)
{
    Mat  image = imread(filename);
    imshow("Image", image);
    if (waitKey(10) >= 0)
        return;
}


//show the video c style
//
void cvShowVideo(char* filename)
{
    cvNamedWindow("Video");
    CvCapture* capture = cvCreateFileCapture(filename);
    IplImage* frame;
    for (;;){
        frame = cvQueryFrame(capture);
        if (!frame)
            break;
        cvShowImage("Video", frame);
        if (cvWaitKey(20) >= 0)
            break;
    }
    //release the resource
    //
    {
        cvReleaseImage(&frame);
        cvReleaseCapture(&capture);
        cvDestroyWindow("Video");
    }
    return;
}
//show the video c++ style
//
void ShowVideo(char* filename)
{
    VideoCapture cap(filename);
    Mat   frame;
    for (;;){
        cap >> frame;
        if (frame.empty())
            break;
        imshow("Video", frame);
        if (waitKey(20) >= 0)
            break;
    }
}

//set ROI in the picture c-style function
//
void cvSetROI(IplImage* image, CvRect rect)
{
    IplImage* roi=image;
    cvSetImageROI(image, rect);
    //todo .....
    cvResetImageROI(image);
}
//set ROI in the picture c++-style function
//
void SetROI(Mat image, Rect rect)
{
    //you can use range or rect
    //1
    Mat  roi = image(rect);
    //2
    Mat roi1 = image(Range(20, 20 + 100), Range(100, 100 + 100));
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值