1
2
3'''
4 This program demonstrates Laplace point/edge detection using
5 OpenCV function Laplacian()
6 It captures from the camera of your choice: 0, 1, ... default 0
7 Usage:
8 python laplace.py <ddepth> <smoothType> <sigma>
9 If no arguments given default arguments will be used.
10
11 Keyboard Shortcuts:
12 Press space bar to exit the program.
13 '''
14
15
16from __future__ import print_function
17
18import numpy as np
19import cv2 as cv
20import sys
21
23
24 ddepth = cv.CV_16S
25 smoothType = "MedianBlur"
26 sigma = 3
27 if len(sys.argv)==4:
28 ddepth = sys.argv[1]
29 smoothType = sys.argv[2]
30 sigma = sys.argv[3]
31
33
36
37 print("=="*40)
38 print("Frame Width: ", cap.get(cv.CAP_PROP_FRAME_WIDTH), "Frame Height: ", cap.get(cv.CAP_PROP_FRAME_HEIGHT), "FPS: ", cap.get(cv.CAP_PROP_FPS))
39 while True:
40
41 ret, frame = cap.read()
42 if ret == False:
43 print("Can't open camera/video stream")
44 break
45
47
48 ksize = (sigma*5)|1
49
50 if smoothType == "GAUSSIAN":
52 if smoothType == "BLUR":
53 smoothed =
cv.blur(frame, (ksize, ksize))
54 if smoothType == "MedianBlur":
56
57
59
61
64 if k == 27:
65 return
66if __name__ == "__main__":
67 print(__doc__)
Class for video capturing from video files, image sequences or cameras.
Definition videoio.hpp:727
void convertScaleAbs(InputArray src, OutputArray dst, double alpha=1, double beta=0)
Scales, calculates absolute values, and converts the result to 8-bit.
int getTrackbarPos(const String &trackbarname, const String &winname)
Returns the trackbar position.
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
int waitKey(int delay=0)
Waits for a pressed key.
void namedWindow(const String &winname, int flags=WINDOW_AUTOSIZE)
Creates a window.
void destroyAllWindows()
Destroys all of the HighGUI windows.
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 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.
void GaussianBlur(InputArray src, OutputArray dst, Size ksize, double sigmaX, double sigmaY=0, int borderType=BORDER_DEFAULT, AlgorithmHint hint=cv::ALGO_HINT_DEFAULT)
Blurs an image using a Gaussian filter.
int main(int argc, char *argv[])
Definition highgui_qt.cpp:3