Can opencv draw a float-coordinate rect in cv::Mat? - opencv

I am tring to use cv::rectangle() to draw a rect in cv::Mat, but could I draw a rect whose four points coordinate value with a float percision ? (like what Qt do in QPainter).

Try Blend2d library it fast and integates easyly with OpenCV:
Simple example:
#include <blend2d.h>
#include "opencv2/opencv.hpp"
int main(int argc, char* argv[])
{
BLImage img(480, 480, BL_FORMAT_PRGB32);
BLContext ctx(img);
// Read an image from file.
cv::Mat I = cv::imread("F:/ImagesForTest/lena.jpg");
cv::cvtColor(I, I, cv::COLOR_RGB2RGBA);
BLImage texture;
//BLResult err = texture.readFromFile("texture.jpeg");
texture.create(512, 512, BL_FORMAT_XRGB32);
memcpy((uchar*)texture.impl->pixelData, (uchar*)I.data, 512 * 512 * 4);
// Create a pattern and use it to fill a rounded-rect.
BLPattern pattern(texture);
ctx.setFillStyle(pattern);
ctx.setCompOp(BL_COMP_OP_SRC_COPY);
ctx.fillAll();
// Coordinates can be specified now or changed later.
BLGradient linear(BLLinearGradientValues(0, 0, 0, 480));
// Color stops can be added in any order.
linear.addStop(0.0, BLRgba32(0xFFFFFFFF));
linear.addStop(0.5, BLRgba32(0xFF5FAFDF));
linear.addStop(1.0, BLRgba32(0xFF2F5FDF));
// `setFillStyle()` can be used for both colors and styles.
ctx.setFillStyle(linear);
ctx.setCompOp(BL_COMP_OP_MODULATE);
ctx.fillRoundRect(40.0, 40.0, 400.0, 400.0, 45.5);
ctx.setStrokeStyle(BLRgba32(0xFFFF0000));
ctx.setStrokeWidth(3);
ctx.strokeLine(0,0,480,480);
ctx.end();
//BLImageCodec codec;
//codec.findByName("BMP");
//img.writeToFile("bl-getting-started-2.bmp", codec);
cv::Mat cvImg(img.height(), img.width(), CV_8UC4, img.impl->pixelData);
cv::imshow("res", cvImg);
cv::waitKey(0);
return 0;
}

Related

How to use RealSense's spatial_filter on an OpenCV Mat?

I want to apply RealSense library's depth filtering (rs2::spatial_filter) on an OpenCV Mat, but it seems like the filter is not being applied. The original depth image and the supposedly filtered depth image look exactly the same.
To load raw depth data into rs2::frame, I used modified #Groch88's answer. One of the changes I made was changing the depth format from RS2_FORMAT_Z16 to RS2_FORMAT_DISTANCE (to be able to load a float depth map) and not loading the RGB part of the frame. The whole source is below.
Why do the original and the filtered images look exactly the same? Am I missing something obvious?
main.cpp:
#include <iostream>
#include <opencv2/opencv.hpp>
#include <librealsense2/rs.hpp>
#include "rsImageConverter.h"
int main()
{
cv::Mat rawDepthImg = load_raw_depth("/path/to/depth/image"); // loads float depth image
rsImageConverter ic{rawDepthImg.cols, rawDepthImg.rows, sizeof(float)};
if ( !ic.convertFrame(rawDepthImg.data, rawDepthImg.data) )
{
fprintf(stderr, "Could not load depth.\n");
exit(1);
}
rs2::frame rsDepthFrame = ic.getDepth();
// Filter
// https://dev.intelrealsense.com/docs/post-processing-filters
rs2::spatial_filter spat_filter;
spat_filter.set_option(RS2_OPTION_FILTER_MAGNITUDE, 2.0f);
spat_filter.set_option(RS2_OPTION_FILTER_SMOOTH_ALPHA, 0.5f);
spat_filter.set_option(RS2_OPTION_FILTER_SMOOTH_DELTA, 20.0f);
// Apply filtering
rs2::frame rsFilteredDepthFrame;
rsFilteredDepthFrame = spat_filter.process(rsDepthFrame);
// Copy filtered depth to OpenCV Mat
cv::Mat filteredDepth = cv::Mat::zeros(rawDepthImg.size(), CV_32F);
memcpy(filteredDepth.data, rsFilteredDepthFrame.get_data(), rawDepthImg.cols * rawDepthImg.rows * sizeof(float));
// Display (un)filtered images
cv::imshow("Original depth", rawDepthImg); // Original image is being shown
cv::imshow("Filtered depth", filteredDepth); // A depth image that looks exactly like the original unfiltered depth map is shown
cv::imshow("Diff", filteredDepth - rawDepthImg); // A black image is being shown
cv::waitKey(0);
return 0;
}
rsImageConverter.h (edited version of #Doch88's code):
#include <librealsense2/rs.hpp>
#include <librealsense2/hpp/rs_internal.hpp>
class rsImageConverter
{
public:
rsImageConverter(int w, int h, int bppDepth);
bool convertFrame(uint8_t* depth_data, uint8_t* color_data);
rs2::frame getDepth() const;
private:
int w = 640;
int h = 480;
int bppDepth = sizeof(float);
rs2::software_device dev;
rs2::software_sensor depth_sensor;
rs2::stream_profile depth_stream;
rs2::syncer syncer;
rs2::frame depth;
int ind = 0;
};
rsImageConverter.cpp (edited version of #Doch88's code):
#include "rsImageConverter.h"
rsImageConverter::rsImageConverter(int w, int h, int bppDepth) :
w(w),
h(h),
bppDepth(bppDepth),
depth_sensor(dev.add_sensor("Depth")) // initializing depth sensor
{
rs2_intrinsics depth_intrinsics{ w, h, (float)(w / 2), (float)(h / 2), (float) w , (float) h , RS2_DISTORTION_BROWN_CONRADY ,{ 0,0,0,0,0 } };
depth_stream = depth_sensor.add_video_stream({ RS2_STREAM_DEPTH, 0, 0,
w, h, 60, bppDepth,
RS2_FORMAT_DISTANCE, depth_intrinsics });
depth_sensor.add_read_only_option(RS2_OPTION_DEPTH_UNITS, 1.f); // setting depth units option to the virtual sensor
depth_sensor.open(depth_stream);
depth_sensor.start(syncer);
}
bool rsImageConverter::convertFrame(uint8_t* depth_data, uint8_t* color_data)
{
depth_sensor.on_video_frame({ depth_data, // Frame pixels
[](void*) {}, // Custom deleter (if required)
w*bppDepth, bppDepth, // Stride and Bytes-per-pixel
(rs2_time_t)ind * 16, RS2_TIMESTAMP_DOMAIN_HARDWARE_CLOCK, ind, // Timestamp, Frame# for potential sync services
depth_stream });
ind++;
rs2::frameset fset = syncer.wait_for_frames();
depth = fset.first_or_default(RS2_STREAM_DEPTH);
return depth;
}
rs2::frame rsImageConverter::getDepth() const
{
return depth;
}

accumulatedweight throws cv:Exception error

I am new to OpenCV and trying to find contours and draw rectangle on them, here's my code but its throwing cv::Exception when it comes to accumulatedweighted().
#include "opencv2/video/tracking.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/imgproc/imgproc_c.h"
#include "opencv2/highgui/highgui.hpp"
#include <iostream>
#include <ctype.h>
using namespace cv;
using namespace std;
static void help()
{
cout << "\nThis is a Example to implement CAMSHIFT to detect multiple motion objects.\n";
}
Rect rect;
VideoCapture capture;
Mat currentFrame, currentFrame_grey, differenceImg, oldFrame_grey,background;
vector<vector<Point> > contours;
vector<Vec4i> hierarchy;
bool first = true;
int main(int argc, char* argv[])
{
//Create a new movie capture object.
capture.open(0);
if(!capture.isOpened())
{
//error in opening the video input
cerr << "Unable to open video file: " /*<< videoFilename*/ << endl;
exit(EXIT_FAILURE);
}
//capture current frame from webcam
capture >> currentFrame;
//Size of the image.
CvSize imgSize;
imgSize.width = currentFrame.size().width; //img.size().width
imgSize.height = currentFrame.size().height; ////img.size().height
//Images to use in the program.
currentFrame_grey.create( imgSize, IPL_DEPTH_8U);//image.create().
while(1)
{
capture >> currentFrame;//VideoCapture& VideoCapture::operator>>(Mat& image)
//Convert the image to grayscale.
cvtColor(currentFrame,currentFrame_grey,CV_RGB2GRAY);//cvtColor()
// Converting Original image to make both background n original image same
currentFrame.convertTo(currentFrame,CV_32FC3);
background = Mat::zeros(currentFrame.size(), CV_32FC3);
//Here its throwing exception
accumulateWeighted(currentFrame,background,1.0,NULL);
imshow("Background",background);
if(first) //Capturing Background for the first time
{
differenceImg = currentFrame_grey.clone();//img1 = img.clone()
oldFrame_grey = currentFrame_grey.clone();//img2 = img.clone()
convertScaleAbs(currentFrame_grey, oldFrame_grey, 1.0, 0.0);//convertscaleabs()
first = false;
continue;
}
//Minus the current frame from the moving average.
absdiff(oldFrame_grey,currentFrame_grey,differenceImg);//absDiff()
//bluring the differnece image
blur(differenceImg, differenceImg, imgSize);//blur()
//apply threshold to discard small unwanted movements
threshold(differenceImg, differenceImg, 25, 255, CV_THRESH_BINARY);//threshold()
//find contours
findContours(differenceImg,contours,hierarchy,CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0)); //findcontours()
//draw bounding box around each contour
//for(; contours! = 0; contours = contours->h_next)
for(int i = 0; i < contours.size(); i++)
{
rect = boundingRect(contours[i]); //extract bounding box for current contour
//drawing rectangle
rectangle(currentFrame, cvPoint(rect.x, rect.y), cvPoint(rect.x+rect.width, rect.y+rect.height), cvScalar(0, 0, 255, 0), 2, 8, 0);
}
//New Background
convertScaleAbs(currentFrame_grey, oldFrame_grey, 1.0, 0.0);
//display colour image with bounding box
imshow("Output Image", currentFrame);//imshow()
//display threshold image
imshow("Difference image", differenceImg);//imshow()
//clear memory and contours
//cvClearMemStorage( storage );
//contours = 0;
contours.clear();
//background = currentFrame;
//press Esc to exit
char c = cvWaitKey(33);
if( c == 27 ) break;
}
// Destroy All Windows.
destroyAllWindows();
return 0;
}
Please Help to solve this.
First of all, I don't really get the idea of calling accumulateWeighted with alpha = 1.0. If you look at the definition of accumulateWeighted in the doc, you will see that with alpha = 1.0 it is basically equivalent to copy currentFrame into background at each iteration.
Moreover, it is an accumulation function, to accumulate image changes over time into a new image. What is the interest of it if you reset background at every loop with background = Mat::zeros(currentFrame.size(), CV_32FC3); ?
This being said, there is a little flaw in your code with the 4th argument of the function. You wrote accumulateWeighted(currentFrame,background,1.0,NULL);. If you look into the documentation you will find that the 4th argument is a Mask, and is optional. Passing a NULL pointer here might be the source of your exception. Why don't you call the function like this : accumulateWeighted(currentFrame,background,1.0); ?
Hope this helps,
Ben

Search multiple colours simultaneously with opencv and c++

I am trying to make the code below search multiple colours at the same time e.g. red, yellow and orange. I have added masks to the code but a cant get them to apply properly what am i doing wrong I am not sure if the line to add the masks to the frame is in the right place or not.
#include "stdafx.h"
#include <cv.h>
#include <highgui.h>
using namespace std;
using namespace cv::gpu;
IplImage* GetThresholdedImage(IplImage* imgHSV){
IplImage* imgThresh=cvCreateImage(cvGetSize(imgHSV),IPL_DEPTH_8U, 1);
cvInRangeS(imgHSV, cvScalar(170,160,60), cvScalar(180,255,256), imgThresh);
return imgThresh;
}
int main(){
//Char Firetype = type;
CvCapture* capture = cvCaptureFromCAM(1);
if(!capture){
printf("Capture failure\n");
return -1;
}
IplImage* frame=0;
cvNamedWindow("Video");
cvNamedWindow("Fire");
cvNamedWindow("Info");
//iterate through each frame of the video
while(true){
frame = cvQueryFrame(capture);
if(!frame) break;
frame=cvCloneImage(frame);
cvSmooth(frame, frame, CV_GAUSSIAN,3,3); //smooth the original image using Gaussian kernel
cv::Mat imgMat(frame);
cv::Mat mask1;
cv::inRange(imgMat, cv::Scalar(20, 100, 100), cv::Scalar(30, 255, 255), mask1);
cv::Mat mask2;
cv::inRange(imgMat, cv::Scalar(170,160,60), cv::Scalar(180,255,256), mask2);
cv::Mat mask3;
cv::inRange(imgMat, cv::Scalar(70,160,60), cv::Scalar(90,255,256), mask3);
// combine them
cv::Mat mask_combined = mask1 | mask2 | mask3;
// now since our frame from the camera is bgr, we have to convert our mask to 3 channels:
cv::Mat mask_rgb;
cv::cvtColor( mask_combined, mask_rgb, CV_GRAY2BGR );
IplImage framemask = imgMat & mask_rgb;
IplImage* imgHSV = cvCreateImage(cvGetSize(framemask), IPL_DEPTH_8U, 3);
cvCvtColor(frame, imgHSV, CV_BGR2HSV); //Change the color format from BGR to HSV
//This function threshold the HSV image and create a binary image
// function below to get b&w image
IplImage* imgThresh = GetThresholdedImage(imgHSV);
cvSmooth(imgThresh, imgThresh, CV_GAUSSIAN,3,3); //smooth the binary image using Gaussian kernel
cvShowImage("Fire", imgThresh);
cvShowImage("Video", frame);
// cvNamedWindow("Info", Firetype);
cvReleaseImage(&imgHSV);
cvReleaseImage(&imgThresh);
cvReleaseImage(&frame);
//Wait 50mS
int c = cvWaitKey(10);
//If 'ESC' is pressed, break the loop
if((char)c==27 ) break;
}
cvDestroyAllWindows() ;
cvReleaseCapture(&capture);
return 0;
}
tl:dr;
use bitwise-or to combine binary masks,
bitwise_and to apply them
cv::Mat mask1;
cv::inRange( hsv, cv::Scalar(20, 100, 100), cv::Scalar(30, 255, 255), mask1);
cv::Mat mask2;
cv::inRange( hsv, cv::Scalar(170,160,60), cv::Scalar(180,255,256), mask2);
cv::Mat mask3;
cv::inRange( hsv, cv::Scalar(70,160,60), cv::Scalar(90,255,256), mask3);
// combine them
cv::Mat mask_combined = mask1 | mask2 | mask3;
// now since our frame from the camera is bgr, we have to convert our mask to 3 channels:
cv::Mat mask_rgb;
cv::cvtColor( mask_combined, mask_rgb, CV_GRAY2BGR );
// finally, apply the mask to our image
frame = frame & mask_rgb;

Detect/Fitting Circles using Hough Transform in OpenCV 2.4.6

The objective is to detect the 5 white circles in the image.The test image in which the circles have to be detected is the one shown here 640x480
Please download the original image here,1280x1024
I am using different methods to bring out a evaluation of various circle/ellipse detection methods. But somehow I am not able to fix my simple Hough transform code. It does not detect any circles. I am not clear whether the problem is with pre-processing step, or the parameters of the HoughCircle. I have gone through all the similar questions in the forum, but still not able to fix the issue. This is my code. Please help me in this regards..
Header file
#ifndef IMGPROCESSOR_H
#define IMGPROCESSOR_H
// OpenCV Library
#include <opencv2\opencv.hpp>
#include <iostream>
using namespace cv;
using namespace std;
class ImgProcessor{
public:
Mat OpImg ;
ImgProcessor();
~ImgProcessor();
//aquire filter methods to image
int Do_Hough(Mat IpImg);
};
#endif /* ImgProcessor_H */
Source file
#include "ImgProcessor.h"
#include <opencv2\opencv.hpp>
#include "opencv2\imgproc\imgproc.hpp"
#include "opencv2\imgproc\imgproc_c.h"
#include <vector>
using namespace cv;
ImgProcessor::ImgProcessor(){
return;
}
ImgProcessor::~ImgProcessor(){
return;
}
//Apply filtering for the input image
int ImgProcessor::Do_Hough(Mat IpImg)
{
//Parameter Initialization________________________________________________________
double sigma_x, sigma_y, thresh=250, max_thresh = 255;
int ksize_w = 5 ;
int ksize_h = 5;
sigma_x = 0.3*((ksize_w-1)*0.5 - 1) + 0.8 ;
sigma_y = 0.3*((ksize_h-1)*0.5 - 1) + 0.8 ;
vector<Vec3f> circles;
//Read the image as a matrix
Mat TempImg;
//resize(IpImg, IpImg ,Size(), 0.5,0.5, INTER_AREA);
//Preprocessing__________________________________________________________
//Perform initial smoothing
GaussianBlur( IpImg, TempImg, Size(ksize_w, ksize_h),2,2);
//perform thresholding
threshold(TempImg,TempImg, thresh,thresh, 0);
//Remove noise by gaussian smoothing
GaussianBlur( TempImg, TempImg, Size(ksize_w, ksize_h),2,2);
/*imshow("Noisefree Image", TempImg);
waitKey(10000);*/
//Obtain edges
Canny(TempImg, TempImg, 255,240 , 3);
imshow("See Edges", TempImg);
waitKey(10000);
//Increase the line thickness
//dilate(TempImg,TempImg,0,Point(-1,-1),3);
//Hough Circle Method______________________________________________________________
// Apply the Hough Transform to find the circles
HoughCircles( TempImg, circles, 3, 1, TempImg.rows/32, 255, 240, 5, 0 );
// Draw the circles detected
for( size_t i = 0; i < circles.size(); i++ )
{
Point center(cvRound(circles[i][0]), cvRound(circles[i][1]));
int radius = cvRound(circles[i][2]);
// circle center
circle( IpImg, center, 3, Scalar(0,255,0), -1, 8, 0 );
// circle outline
circle( IpImg, center, radius, Scalar(0,0,255), 3, 8, 0 );
}
// Show your results
namedWindow( "Hough Circle Transform", WINDOW_AUTOSIZE );
imshow( "Hough Circle Transform", IpImg );
// waitKey(0);
return 0;
}
int main(int argc, char** argv)
{
ImgProcessor Iclass;
//char* imageName = argv[1];
string imageName = "D:/Projects/test_2707/test_2707/1.bmp";
Mat IpImg = imread( imageName );
cvtColor(IpImg, IpImg,6,CV_8UC1);
Iclass.Do_Hough(IpImg);
/*Iclass.Do_Contours(IpImg);*/
return 0;
}
The code seems fine, other than for:
HoughCircles( TempImg, circles, 3, 1, TempImg.rows/32, 255, 240, 5, 0 );
Does number 3 in the parameter list correspond to CV_HOUGH_GRADIENT ? It is always better to use definitions instead of numbers.
May be you should test it first with an image with bigger circles. Once you are sure that the rest of the code is correct, you can tune the parameters of HoughCircles.

How to capture the desktop in OpenCV (ie. turn a bitmap into a Mat)?

I want to use OpenCV to process my desktop as if it were a video stream.
I am familiar with OpenCV.
I am not familiar with the Windows API.
I realize there are other ways to capture the screen, but for the purposes of my question, I need it to be done using OpenCV.
Here is my (super naive) code:
HWND hDesktopWnd;
HDC hDesktopDC;
hDesktopWnd=GetDesktopWindow();
hDesktopDC=GetDC(hDesktopWnd);
// get the height and width of the screen
int height = GetSystemMetrics(SM_CYVIRTUALSCREEN);
int width = GetSystemMetrics(SM_CXVIRTUALSCREEN);
// create a bitmap
HBITMAP hbDesktop = CreateCompatibleBitmap( hDesktopDC, width, height);
Mat src(height,width,CV_8UC4);
src.data = (uchar*)hbDesktop;
imshow("output",src); //fails :(
There are similar questions on StackOverflow, but they are either for the old-style OpenCV, or for Android operating system.
I'm on windows 7 64x
Opencv 2.4.3
Thanks anyone who can answer this question.
After MUCH trial and error, I managed to write a function to do it. here it is for anyone else who might want it:
#include "stdafx.h"
#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <opencv2/highgui/highgui.hpp>
#include <Windows.h>
#include <iostream>
#include <string>
using namespace std;
using namespace cv;
Mat hwnd2mat(HWND hwnd){
HDC hwindowDC,hwindowCompatibleDC;
int height,width,srcheight,srcwidth;
HBITMAP hbwindow;
Mat src;
BITMAPINFOHEADER bi;
hwindowDC=GetDC(hwnd);
hwindowCompatibleDC=CreateCompatibleDC(hwindowDC);
SetStretchBltMode(hwindowCompatibleDC,COLORONCOLOR);
RECT windowsize; // get the height and width of the screen
GetClientRect(hwnd, &windowsize);
srcheight = windowsize.bottom;
srcwidth = windowsize.right;
height = windowsize.bottom/2; //change this to whatever size you want to resize to
width = windowsize.right/2;
src.create(height,width,CV_8UC4);
// create a bitmap
hbwindow = CreateCompatibleBitmap( hwindowDC, width, height);
bi.biSize = sizeof(BITMAPINFOHEADER); //http://msdn.microsoft.com/en-us/library/windows/window/dd183402%28v=vs.85%29.aspx
bi.biWidth = width;
bi.biHeight = -height; //this is the line that makes it draw upside down or not
bi.biPlanes = 1;
bi.biBitCount = 32;
bi.biCompression = BI_RGB;
bi.biSizeImage = 0;
bi.biXPelsPerMeter = 0;
bi.biYPelsPerMeter = 0;
bi.biClrUsed = 0;
bi.biClrImportant = 0;
// use the previously created device context with the bitmap
SelectObject(hwindowCompatibleDC, hbwindow);
// copy from the window device context to the bitmap device context
StretchBlt( hwindowCompatibleDC, 0,0, width, height, hwindowDC, 0, 0,srcwidth,srcheight, SRCCOPY); //change SRCCOPY to NOTSRCCOPY for wacky colors !
GetDIBits(hwindowCompatibleDC,hbwindow,0,height,src.data,(BITMAPINFO *)&bi,DIB_RGB_COLORS); //copy from hwindowCompatibleDC to hbwindow
// avoid memory leak
DeleteObject (hbwindow); DeleteDC(hwindowCompatibleDC); ReleaseDC(hwnd, hwindowDC);
return src;
}
A better way to do it is do it while allocating memory to the pixels only once. so the only copy done here is the one that made by BitBlt
int main()
{
int x_size = 800, y_size = 600; // <-- Your res for the image
HBITMAP hBitmap; // <-- The image represented by hBitmap
Mat matBitmap; // <-- The image represented by mat
// Initialize DCs
HDC hdcSys = GetDC(NULL); // Get DC of the target capture..
HDC hdcMem = CreateCompatibleDC(hdcSys); // Create compatible DC
void *ptrBitmapPixels; // <-- Pointer variable that will contain the potinter for the pixels
// Create hBitmap with Pointer to the pixels of the Bitmap
BITMAPINFO bi; HDC hdc;
ZeroMemory(&bi, sizeof(BITMAPINFO));
bi.bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
bi.bmiHeader.biWidth = x_size;
bi.bmiHeader.biHeight = -y_size; //negative so (0,0) is at top left
bi.bmiHeader.biPlanes = 1;
bi.bmiHeader.biBitCount = 32;
hdc = GetDC(NULL);
hBitmap = CreateDIBSection(hdc, &bi, DIB_RGB_COLORS, &ptrBitmapPixels, NULL, 0);
// ^^ The output: hBitmap & ptrBitmapPixels
// Set hBitmap in the hdcMem
SelectObject(hdcMem, hBitmap);
// Set matBitmap to point to the pixels of the hBitmap
matBitmap = Mat(y_size, x_size, CV_8UC4, ptrBitmapPixels, 0);
// ^^ note: first it is y, then it is x. very confusing
// * SETUP DONE *
// Now update the pixels using BitBlt
BitBlt(hdcMem, 0, 0, x_size, y_size, hdcSys, 0, 0, SRCCOPY);
// Just to do some image processing on the pixels.. (Dont have to to this)
Mat matRef = matBitmap(Range(100, 200), Range(100, 200));
// y1 y2 x1 x2
bitwise_not(matRef, matRef); // Invert the colors in this x1,x2,y1,y2
// Display the results through Mat
imshow("Title", matBitmap);
// Wait until some key is pressed
waitKey(0);
return 0;
}
Note that no error handling done here to make it simple to understand but you have to do error handling in your code!
Hope this helps

Resources