Port to OpenCV4 and use the C++ API for everything
authorAntonio Ospite <ao2@ao2.it>
Sat, 10 Oct 2020 16:47:04 +0000 (18:47 +0200)
committerAntonio Ospite <ao2@ao2.it>
Sat, 10 Oct 2020 16:47:04 +0000 (18:47 +0200)
Makefile
Segmentation.hpp
opencv_trail_effect.cpp

index 4e316b9..75dde40 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -1,4 +1,4 @@
-CXXFLAGS = -ansi -pedantic -pedantic-errors -Wall -g3 -O2 -D_ANSI_SOURCE_
+CXXFLAGS = -std=c++11 -pedantic -pedantic-errors -Wall -g3 -O2 -D_ANSI_SOURCE_
 CXXFLAGS += -fno-common \
            -fvisibility=hidden \
            -Wall \
@@ -34,8 +34,8 @@ ifeq ($(COMPILER), clang)
   LDFLAGS += -Qunused-arguments
 endif
 
-CXXFLAGS += $(shell pkg-config --cflags opencv)
-LDLIBS += $(shell pkg-config --libs opencv)
+CXXFLAGS += $(shell pkg-config --cflags opencv4)
+LDLIBS += $(shell pkg-config --libs opencv4)
 
 LINK.o = $(LINK.cpp)
 opencv_trail_effect:
index 5e87326..9ad76d7 100644 (file)
@@ -51,8 +51,8 @@ public:
                cv::Mat gray_frame;
                cv::Mat frame_mask;
 
-               cvtColor(frame, gray_frame, CV_RGB2GRAY);
-               cv::threshold(gray_frame, frame_mask, threshold, 255, CV_THRESH_TOZERO);
+               cvtColor(frame, gray_frame, cv::COLOR_RGB2GRAY);
+               cv::threshold(gray_frame, frame_mask, threshold, 255, cv::THRESH_TOZERO);
 
                return frame_mask;
        }
@@ -84,7 +84,7 @@ public:
                pMOG2->apply(frame, foreground_mask, 0);
                cv::erode(foreground_mask, foreground_mask, cv::Mat());
                cv::dilate(foreground_mask, foreground_mask, cv::Mat());
-               cv::threshold(foreground_mask, foreground_mask, 0, 255, CV_THRESH_OTSU);
+               cv::threshold(foreground_mask, foreground_mask, 0, 255, cv::THRESH_OTSU);
                cv::medianBlur(foreground_mask, foreground_mask, 9);
 
                return foreground_mask;
index 6c0d09c..357cc42 100644 (file)
@@ -142,15 +142,15 @@ int main(int argc, char *argv[])
                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);
+               int fps = inputVideo.get(cv::CAP_PROP_FPS);
                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;
@@ -176,7 +176,7 @@ int main(int argc, char *argv[])
        if (*segmentation_method == "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);
@@ -191,7 +191,7 @@ int main(int argc, char *argv[])
                goto out_delete_trail;
        }
 
-       cv::namedWindow("Frame", CV_WINDOW_NORMAL);
+       cv::namedWindow("Frame", cv::WINDOW_NORMAL);
 
        for (;;) {
                inputVideo >> input_frame;