Opencv C++ Tutorial, Mat Roi, Region of interest
Simple opencv C++ tutorial on how to work with ROI. Code example about selecting the rectangle region of interest inside the image and cutting or displaying part of the image from the bigger picture. There is nothing that is difficult about this. The only trick is about one line of code.
Rect RectangleToSelect(x,y,width,height)
Mat source;
Mat roiImage = source(RectangleToSelect);
This is the first post from this series. These simple OpenCV tutorials are all over the web. I would like to visualize all my steps through the code and //comment on them. Each tutorial will contain a small amount of steps to keep the reader focused. The first tutorial about mat resizeing is available under the link Mat Resize
I am using Visual Studio 2015, How to use Opencv 3.0.0 with Visual Studio can be found here install opencv visual studio 2015. Visual studio 2015 is the best option to use NuGet packages, Here is described how to install Opencv by NUGET. It is easy. Working under one minute after you find the NuGet packages console.
Opencv select mat ROI tutorial example
Dive directly into ROI
#include <Windows.h>
#include "opencv2\highgui.hpp"
#include "opencv2\imgproc.hpp"
#include "opencv2/video/background_segm.hpp"
#include "opencv2/video/tracking.hpp"
using namespace cv;
using namespace std;
int main(int argc, const char** argv)
{
//
// Load the image from file
//
Mat LoadedImage;
// Just loaded image Lenna.png from project dir to LoadedImage Mat
LoadedImage = imread("Lenna.png", IMREAD_COLOR);
//I would like to visualize Mat step by step to see the result immediately.
// Show what is in the Mat after load
namedWindow("Step 1 image loaded", WINDOW_AUTOSIZE);
imshow("Step 1 image loaded", LoadedImage);
waitKey(1000);
// Same the result from LoadedImage to Step1.JPG
imwrite("Step1.JPG", LoadedImage);
// This construct Rectangle Rec start at x=100 y=100, width=200 and heigth=200
Rect Rec(100, 100, 200, 200);
//Draw the rectangle into LoadedImage
//Parameters are (into Mat, Rec describe position where to draw rectangle
// Scalar is Color, 1 is thickness, 8 is line type and 0 shift position
rectangle(LoadedImage, Rec, Scalar(255), 1, 8, 0);
// Show what rectangle
namedWindow("Step 2 draw Rectangle", WINDOW_AUTOSIZE);
imshow("Step 2 draw Rectangle", LoadedImage);
waitKey(1000);
// Same the result from LoadedImage to Step2.JPG
imwrite("Step2.JPG", LoadedImage);
//Select area described by REC and result write to the Roi
Mat Roi = LoadedImage(Rec);
namedWindow("Step 3 Draw selected Roi", WINDOW_AUTOSIZE);
imshow("Step 3 Draw selected Roi", Roi);
waitKey(1000);
// Same the result from LoadedImage to Step3.JPG
imwrite("Step3.JPG", Roi);
// Put roi back into the source image
// If you want to show the details and
// visualize with context of source image
// This rectangle describes the target, where you want to
// put your roi into the original image
// !! width and height of where rect must match Roi size
// Let put our Roi into origin
Rect WhereRec(0, 0, Roi.cols, Roi.rows);
// This copy Roi Image into loaded on position Where rec
Roi.copyTo(LoadedImage(WhereRec));
namedWindow("Step 4 Final result", WINDOW_AUTOSIZE);
imshow("Step 4 Final result", LoadedImage);
waitKey(1000);
// Same the result from LoadedImage to Step4.JPG
imwrite("Step4.JPG", LoadedImage);
}
good idea...
แทงบอล sbobet
หวยออนไลน์
royal1688
ทางเข้า maxbet
Why are you focusing on the hat?
ทางเข้า maxbet
m8bet
m8bet
I'm wondering.. what is the difference between the uses of / and \ at #include ""? thank you
One should use uniform / and \ dependent of the OS one is using.
In Windows: #include "opencv2\imgproc.hpp"
In Linux: #include "opencv2/video/background_segm.hpp"
Thank you a lot. I posted very interesting research on OpenCv development here Feel free to check and ask me questions
Very good.
gclub
goldenslot
This comment has been removed by the author.
maxbet
maxbet
This comment has been removed by the author.
เว็บไซด์ยอดนิยมอันดับหนึ่งของประเทศไทย มีกีฬาหลากหลายชนิดให้ร่วมสนุก เช่น ฟุตบอล เทนนิส บาสเกตบอล ชกมวย เบสบอล เป็นต้น ร่วมลุ้นร่วมสนุกได้ทุกวัน เพียงเข้าไปที่
จีคลับ
จีคลับ
ร้อยไหมปรับรูปหน้า ปรับรูปหน้าที่ไหไนดี ร้อยไหมที่ใดดี? กังนัมสถานพยาบาลเป็นคำตอบไม่ว่าจะเป็น ร้อยไหมหน้าเรียว เป็นวีไลน์แบบประเทศเกาหลีด้วยไหมก้าง ให้ท่านงามแบบประเทศเกาหลี ลดอายุ หน้าเด็ก ไม่เจ็บ ไม่บอบช้ำ ไม่บวม หน้าเป็นวีเชฟ ลดเหนียง เหนียงกระชับสมปรารถนาร้อยไหม
ร้อยไหมหน้าเรียว
ร้อยไหม วีเชฟ
c++ language program codes to beginner coders
cplusplus code binary search tree