Skip to content

Instantly share code, notes, and snippets.

@lecram
Created February 18, 2014 16:28
Show Gist options
  • Save lecram/9074285 to your computer and use it in GitHub Desktop.
Save lecram/9074285 to your computer and use it in GitHub Desktop.
Exemplo de utilização da classe cv::Rect para extrair uma região de interesse (ROI) de uma imagem.
/* g++ -o exrect `pkg-config --libs opencv` exrect.cpp */
#include <iostream>
#include "opencv2/opencv.hpp"
using namespace std;
using namespace cv;
int main(int argc, char *argv[])
{
if (argc != 2) {
cout << "usage:" << endl << argv[0] << " input" << endl;
return 1;
}
Mat img1, img2;
Rect r(240, 230, 70, 60);
img1 = imread(argv[1]);
r += Point(70, 0);
//r += Size(0, 100);
img2 = img1(r);
cvtColor(img2, img2, CV_BGR2GRAY);
namedWindow("Janela1");
namedWindow("Janela2");
//resize(img1, img1, Size(400, 400));
//resize(img2, img2, Size(400, 400));
imshow("Janela1", img1);
imshow("Janela2", img2);
moveWindow("Janela1", 0, 0);
moveWindow("Janela2", r.x, r.y);
while (waitKey(100) != 'q');
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment