/*
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));
}
opencv ROI
最新推荐文章于 2020-03-04 16:52:03 发布