Loading...
Searching...
No Matches
samples/cpp/laplace.cpp
An example using Laplace transformations for edge detection
#include "opencv2/videoio.hpp"
#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include <ctype.h>
#include <stdio.h>
#include <iostream>
using namespace cv;
using namespace std;
static void help(char** argv)
{
cout <<
"\nThis program demonstrates Laplace point/edge detection using OpenCV function Laplacian()\n"
"It captures from the camera of your choice: 0, 1, ... default 0\n"
"Call:\n"
<< argv[0] << " -c=<camera #, default 0> -p=<index of the frame to be decoded/captured next>\n" << endl;
}
enum {GAUSSIAN, BLUR, MEDIAN};
int sigma = 3;
int smoothType = GAUSSIAN;
int main( int argc, char** argv )
{
help(argv);
VideoCapture cap;
if (camera.size() == 1 && isdigit(camera[0]))
else
cap.open(samples::findFileOrKeep(camera));
{
cerr << "Can't open camera/video stream: " << camera << endl;
return 1;
}
cout << "Video " << parser.get<string>("c") <<
": width=" << cap.get(CAP_PROP_FRAME_WIDTH) <<
", height=" << cap.get(CAP_PROP_FRAME_HEIGHT) <<
", nframes=" << cap.get(CAP_PROP_FRAME_COUNT) << endl;
int pos = 0;
if (parser.has("p"))
{
pos = parser.get<int>("p");
}
if (!parser.check())
{
parser.printErrors();
return -1;
}
if (pos != 0)
{
cout << "seeking to frame #" << pos << endl;
{
cerr << "ERROR: seekeing is not supported" << endl;
}
}
namedWindow("Laplacian", WINDOW_AUTOSIZE);
Mat smoothed, laplace, result;
for(;;)
{
Mat frame;
cap >> frame;
break;
int ksize = (sigma*5)|1;
if(smoothType == GAUSSIAN)
else if(smoothType == BLUR)
else
medianBlur(frame, smoothed, ksize);
convertScaleAbs(laplace, result, (sigma+1)*0.25);
imshow("Laplacian", result);
char c = (char)waitKey(30);
if( c == ' ' )
smoothType = smoothType == GAUSSIAN ? BLUR : smoothType == BLUR ? MEDIAN : GAUSSIAN;
if( c == 'q' || c == 'Q' || c == 27 )
break;
}
return 0;
}
Class for video capturing from video files, image sequences or cameras.
Definition: videoio.hpp:728
virtual bool open(const String &filename, int apiPreference=CAP_ANY)
Opens a video file or a capturing device or an IP video stream for video capturing.
virtual bool isOpened() const
Returns true if video capturing has been initialized already.
virtual double get(int propId) const
Returns the specified VideoCapture property.
void convertScaleAbs(InputArray src, OutputArray dst, double alpha=1, double beta=0)
Scales, calculates absolute values, and converts the result to 8-bit.
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
int createTrackbar(const String &trackbarname, const String &winname, int *value, int count, TrackbarCallback onChange=0, void *userdata=0)
Creates a trackbar and attaches it to the specified window.
void medianBlur(InputArray src, OutputArray dst, int ksize)
Blurs an image using the median filter.
void blur(InputArray src, OutputArray dst, Size ksize, Point anchor=Point(-1,-1), int borderType=BORDER_DEFAULT)
Blurs an image using the normalized box filter.
void GaussianBlur(InputArray src, OutputArray dst, Size ksize, double sigmaX, double sigmaY=0, int borderType=BORDER_DEFAULT)
Blurs an image using a Gaussian filter.
void Laplacian(InputArray src, OutputArray dst, int ddepth, int ksize=1, double scale=1, double delta=0, int borderType=BORDER_DEFAULT)
Calculates the Laplacian of an image.
"black box" representation of the file storage associated with a file on disk.
Definition: core.hpp:106
STL namespace.