projects
/
experiments
/
opencv_trail_effect.git
/ blobdiff
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
opencv_trail_effect.cpp: set window size and title
[experiments/opencv_trail_effect.git]
/
opencv_trail_effect.cpp
diff --git
a/opencv_trail_effect.cpp
b/opencv_trail_effect.cpp
index
5fec5dc
..
98e3aed
100644
(file)
--- a/
opencv_trail_effect.cpp
+++ b/
opencv_trail_effect.cpp
@@
-71,13
+71,13
@@
int main(int argc, char *argv[])
int ret = 0;
int opt;
int ret = 0;
int opt;
- std::string
*input_file = NULL
;
- std::string
*output_file = NULL
;
+ std::string
input_file
;
+ std::string
output_file
;
int trail_lenght = 25;
int trail_lenght = 25;
- std::string
*segmentation_method = new std::string
("background");
+ std::string
segmentation_method
("background");
int background_learn_frames = 50;
int threshold_level = 5;
int background_learn_frames = 50;
int threshold_level = 5;
- std::string
*drawing_method = new std::string
("copy");
+ std::string
drawing_method
("copy");
bool reverse_trail = false;
bool show_background = false;
bool redraw_current_frame = false;
bool reverse_trail = false;
bool show_background = false;
bool redraw_current_frame = false;
@@
-85,17
+85,16
@@
int main(int argc, char *argv[])
while ((opt = getopt(argc, argv, "i:o:l:s:b:t:d:rBFh")) != -1) {
switch (opt) {
case 'i':
while ((opt = getopt(argc, argv, "i:o:l:s:b:t:d:rBFh")) != -1) {
switch (opt) {
case 'i':
- input_file =
new
std::string(optarg);
+ input_file = std::string(optarg);
break;
case 'o':
break;
case 'o':
- output_file =
new
std::string(optarg);
+ output_file = std::string(optarg);
break;
case 'l':
trail_lenght = atoi(optarg);
break;
case 's':
break;
case 'l':
trail_lenght = atoi(optarg);
break;
case 's':
- delete segmentation_method;
- segmentation_method = new std::string(optarg);
+ segmentation_method = std::string(optarg);
break;
case 'b':
background_learn_frames = atoi(optarg);
break;
case 'b':
background_learn_frames = atoi(optarg);
@@
-104,8
+103,7
@@
int main(int argc, char *argv[])
threshold_level = atoi(optarg);
break;
case 'd':
threshold_level = atoi(optarg);
break;
case 'd':
- delete drawing_method;
- drawing_method = new std::string(optarg);
+ drawing_method = std::string(optarg);
break;
case 'r':
reverse_trail = true;
break;
case 'r':
reverse_trail = true;
@@
-130,10
+128,17
@@
int main(int argc, char *argv[])
cv::Size frame_size;
cv::Mat input_frame;
cv::Size frame_size;
cv::Mat input_frame;
- if (
input_file
) {
- inputVideo.open(
*
input_file);
+ if (
!input_file.empty()
) {
+ inputVideo.open(input_file);
} else {
} else {
+#ifdef __linux__
+ // XXX Hardcode the V4L2 backend on linux for now because the
+ // GStreamer one lacks some functionality, see:
+ // https://github.com/opencv/opencv/issues/18562
+ inputVideo.open(0, cv::CAP_V4L2);
+#else
inputVideo.open(0);
inputVideo.open(0);
+#endif
}
if (!inputVideo.isOpened()) {
}
if (!inputVideo.isOpened()) {
@@
-142,15
+147,15
@@
int main(int argc, char *argv[])
goto out;
}
goto out;
}
- frame_size = cv::Size((int) inputVideo.get(
CV_
CAP_PROP_FRAME_WIDTH),
- (int) inputVideo.get(
CV_
CAP_PROP_FRAME_HEIGHT));
+ frame_size = cv::Size((int) inputVideo.get(
cv::
CAP_PROP_FRAME_WIDTH),
+ (int) inputVideo.get(
cv::
CAP_PROP_FRAME_HEIGHT));
- if (
output_file
) {
- int fps = inputVideo.get(
CV_
CAP_PROP_FPS);
+ if (
!output_file.empty()
) {
+ int fps = inputVideo.get(
cv::
CAP_PROP_FPS);
if (fps < 0)
fps = 25;
if (fps < 0)
fps = 25;
- outputVideo.open(
*output_file, CV_FOURCC
('M','J','P','G'), fps, frame_size, true);
+ outputVideo.open(
output_file, cv::VideoWriter::fourcc
('M','J','P','G'), fps, frame_size, true);
if (!outputVideo.isOpened()) {
std::cerr << "Could not open the output video for write." << std::endl;
ret = -1;
if (!outputVideo.isOpened()) {
std::cerr << "Could not open the output video for write." << std::endl;
ret = -1;
@@
-166,24
+171,24
@@
int main(int argc, char *argv[])
trail->setRedrawCurrentFrame(redraw_current_frame);
trail->setRedrawCurrentFrame(redraw_current_frame);
- if (trail->setDrawingMethod(
*
drawing_method) < 0) {
+ if (trail->setDrawingMethod(drawing_method) < 0) {
std::cerr << "Invalid drawing method." << std::endl;
ret = -1;
goto out_delete_trail;
}
Segmentation *segmentation;
std::cerr << "Invalid drawing method." << std::endl;
ret = -1;
goto out_delete_trail;
}
Segmentation *segmentation;
- if (
*
segmentation_method == "background") {
+ if (segmentation_method == "background") {
segmentation = new MOG2Segmentation(inputVideo, background_learn_frames);
if (show_background) {
segmentation = new MOG2Segmentation(inputVideo, background_learn_frames);
if (show_background) {
- cv::Mat background(frame_size, inputVideo.get(
CV_
CAP_PROP_FORMAT));
+ cv::Mat background(frame_size, inputVideo.get(
cv::
CAP_PROP_FORMAT));
((MOG2Segmentation *)segmentation)->getBackgroundImage(background);
trail->setBackground(background);
}
((MOG2Segmentation *)segmentation)->getBackgroundImage(background);
trail->setBackground(background);
}
- } else if (
*
segmentation_method == "threshold") {
+ } else if (segmentation_method == "threshold") {
segmentation = new ThresholdSegmentation(threshold_level);
segmentation = new ThresholdSegmentation(threshold_level);
- } else if (
*
segmentation_method == "none") {
+ } else if (segmentation_method == "none") {
segmentation = new DummySegmentation();
} else {
std::cerr << "Invalid segmentation method." << std::endl;
segmentation = new DummySegmentation();
} else {
std::cerr << "Invalid segmentation method." << std::endl;
@@
-191,7
+196,9
@@
int main(int argc, char *argv[])
goto out_delete_trail;
}
goto out_delete_trail;
}
- cv::namedWindow("Frame", CV_WINDOW_AUTOSIZE);
+ cv::namedWindow("Frame", cv::WINDOW_NORMAL);
+ cv::resizeWindow("Frame", frame_size);
+ cv::setWindowTitle("Frame", "OpenCV Trail Effect");
for (;;) {
inputVideo >> input_frame;
for (;;) {
inputVideo >> input_frame;
@@
-218,9
+225,5
@@
int main(int argc, char *argv[])
out_delete_trail:
delete trail;
out:
out_delete_trail:
delete trail;
out:
- delete drawing_method;
- delete segmentation_method;
- delete output_file;
- delete input_file;
return ret;
}
return ret;
}