Added support of GPU in stitching seam estimators
authorAlexey Spizhevoy <no@email>
Mon, 26 Sep 2011 07:57:05 +0000 (07:57 +0000)
committerAlexey Spizhevoy <no@email>
Mon, 26 Sep 2011 07:57:05 +0000 (07:57 +0000)
modules/stitching/include/opencv2/stitching/detail/seam_finders.hpp
modules/stitching/src/seam_finders.cpp
modules/stitching/src/stitcher.cpp
samples/cpp/stitching_detailed.cpp

index 4151598..bd21958 100644 (file)
@@ -51,9 +51,6 @@ namespace detail {
 class CV_EXPORTS SeamFinder\r
 {\r
 public:\r
-    enum { NO, VORONOI, GC_COLOR, GC_COLOR_GRAD };\r
-    static Ptr<SeamFinder> createDefault(int type);\r
-\r
     virtual ~SeamFinder() {}\r
     virtual void find(const std::vector<Mat> &src, const std::vector<Point> &corners,\r
                       std::vector<Mat> &masks) = 0;\r
@@ -89,10 +86,16 @@ private:
 };\r
 \r
 \r
-class CV_EXPORTS GraphCutSeamFinder : public SeamFinder\r
+class CV_EXPORTS GraphCutSeamFinderBase\r
 {\r
 public:\r
     enum { COST_COLOR, COST_COLOR_GRAD };\r
+};\r
+\r
+\r
+class CV_EXPORTS GraphCutSeamFinder : public GraphCutSeamFinderBase, public SeamFinder\r
+{\r
+public:\r
     GraphCutSeamFinder(int cost_type = COST_COLOR_GRAD, float terminal_cost = 10000.f,\r
                        float bad_region_penalty = 1000.f);\r
 \r
@@ -105,6 +108,33 @@ private:
     Ptr<Impl> impl_;\r
 };\r
 \r
+\r
+#ifndef ANDROID\r
+class CV_EXPORTS GraphCutSeamFinderGpu : public GraphCutSeamFinderBase, public PairwiseSeamFinder\r
+{\r
+public:\r
+    GraphCutSeamFinderGpu(int cost_type = COST_COLOR_GRAD, float terminal_cost = 10000.f,\r
+                          float bad_region_penalty = 1000.f)\r
+                          : cost_type_(cost_type), terminal_cost_(terminal_cost), \r
+                            bad_region_penalty_(bad_region_penalty) {}\r
+\r
+    void find(const std::vector<cv::Mat> &src, const std::vector<cv::Point> &corners, \r
+              std::vector<cv::Mat> &masks);\r
+    void findInPair(size_t first, size_t second, Rect roi);\r
+\r
+private:\r
+    void setGraphWeightsColor(const cv::Mat &img1, const cv::Mat &img2, const cv::Mat &mask1, const cv::Mat &mask2,\r
+                              cv::Mat &terminals, cv::Mat &leftT, cv::Mat &rightT, cv::Mat &top, cv::Mat &bottom);\r
+    void setGraphWeightsColorGrad(const cv::Mat &img1, const cv::Mat &img2, const cv::Mat &dx1, const cv::Mat &dx2, \r
+                                  const cv::Mat &dy1, const cv::Mat &dy2, const cv::Mat &mask1, const cv::Mat &mask2, \r
+                                  cv::Mat &terminals, cv::Mat &leftT, cv::Mat &rightT, cv::Mat &top, cv::Mat &bottom);\r
+    std::vector<Mat> dx_, dy_;\r
+    int cost_type_;\r
+    float terminal_cost_;\r
+    float bad_region_penalty_;\r
+};\r
+#endif\r
+\r
 } // namespace detail\r
 } // namespace cv\r
 \r
index 7a964bf..00b6426 100644 (file)
 \r
 #include "precomp.hpp"\r
 \r
-using namespace std;\r
-\r
 namespace cv {\r
 namespace detail {\r
 \r
-Ptr<SeamFinder> SeamFinder::createDefault(int type)\r
-{\r
-    if (type == NO)\r
-        return new NoSeamFinder();\r
-    if (type == VORONOI)\r
-        return new VoronoiSeamFinder();\r
-    if (type == GC_COLOR)\r
-        return new GraphCutSeamFinder(GraphCutSeamFinder::COST_COLOR);\r
-    if (type == GC_COLOR_GRAD)\r
-        return new GraphCutSeamFinder(GraphCutSeamFinder::COST_COLOR_GRAD);\r
-    CV_Error(CV_StsBadArg, "unsupported seam finding method");\r
-    return NULL;\r
-}\r
-\r
-\r
 void PairwiseSeamFinder::find(const vector<Mat> &src, const vector<Point> &corners,\r
-                                  vector<Mat> &masks)\r
+                              vector<Mat> &masks)\r
 {\r
     LOGLN("Finding seams...");\r
     int64 t = getTickCount();\r
@@ -167,7 +150,7 @@ private:
 \r
 \r
 void GraphCutSeamFinder::Impl::find(const vector<Mat> &src, const vector<Point> &corners,\r
-                                        vector<Mat> &masks)\r
+                                    vector<Mat> &masks)\r
 {\r
     // Compute gradients\r
     dx_.resize(src.size());\r
@@ -198,7 +181,7 @@ void GraphCutSeamFinder::Impl::find(const vector<Mat> &src, const vector<Point>
 \r
 \r
 void GraphCutSeamFinder::Impl::setGraphWeightsColor(const Mat &img1, const Mat &img2,\r
-                                                        const Mat &mask1, const Mat &mask2, GCGraph<float> &graph)\r
+                                                    const Mat &mask1, const Mat &mask2, GCGraph<float> &graph)\r
 {\r
     const Size img_size = img1.size();\r
 \r
@@ -407,6 +390,333 @@ void GraphCutSeamFinder::find(const vector<Mat> &src, const vector<Point> &corne
     impl_->find(src, corners, masks);\r
 }\r
 \r
+\r
+#ifndef ANDROID\r
+void GraphCutSeamFinderGpu::find(const vector<Mat> &src, const vector<Point> &corners,\r
+                                 vector<Mat> &masks)\r
+{\r
+    // Compute gradients\r
+    dx_.resize(src.size());\r
+    dy_.resize(src.size());\r
+    Mat dx, dy;\r
+    for (size_t i = 0; i < src.size(); ++i)\r
+    {\r
+        CV_Assert(src[i].channels() == 3);\r
+        Sobel(src[i], dx, CV_32F, 1, 0);\r
+        Sobel(src[i], dy, CV_32F, 0, 1);\r
+        dx_[i].create(src[i].size(), CV_32F);\r
+        dy_[i].create(src[i].size(), CV_32F);\r
+        for (int y = 0; y < src[i].rows; ++y)\r
+        {\r
+            const Point3f* dx_row = dx.ptr<Point3f>(y);\r
+            const Point3f* dy_row = dy.ptr<Point3f>(y);\r
+            float* dx_row_ = dx_[i].ptr<float>(y);\r
+            float* dy_row_ = dy_[i].ptr<float>(y);\r
+            for (int x = 0; x < src[i].cols; ++x)\r
+            {\r
+                dx_row_[x] = normL2(dx_row[x]);\r
+                dy_row_[x] = normL2(dy_row[x]);\r
+            }\r
+        }\r
+    }\r
+    PairwiseSeamFinder::find(src, corners, masks);\r
+}\r
+\r
+\r
+void GraphCutSeamFinderGpu::findInPair(size_t first, size_t second, Rect roi)\r
+{\r
+    Mat img1 = images_[first], img2 = images_[second];\r
+    Mat dx1 = dx_[first], dx2 = dx_[second];\r
+    Mat dy1 = dy_[first], dy2 = dy_[second];\r
+    Mat mask1 = masks_[first], mask2 = masks_[second];\r
+    Point tl1 = corners_[first], tl2 = corners_[second];\r
+\r
+    const int gap = 10;\r
+    Mat subimg1(roi.height + 2 * gap, roi.width + 2 * gap, CV_32FC3);\r
+    Mat subimg2(roi.height + 2 * gap, roi.width + 2 * gap, CV_32FC3);\r
+    Mat submask1(roi.height + 2 * gap, roi.width + 2 * gap, CV_8U);\r
+    Mat submask2(roi.height + 2 * gap, roi.width + 2 * gap, CV_8U);\r
+    Mat subdx1(roi.height + 2 * gap, roi.width + 2 * gap, CV_32F);\r
+    Mat subdy1(roi.height + 2 * gap, roi.width + 2 * gap, CV_32F);\r
+    Mat subdx2(roi.height + 2 * gap, roi.width + 2 * gap, CV_32F);\r
+    Mat subdy2(roi.height + 2 * gap, roi.width + 2 * gap, CV_32F);\r
+\r
+    // Cut subimages and submasks with some gap\r
+    for (int y = -gap; y < roi.height + gap; ++y)\r
+    {\r
+        for (int x = -gap; x < roi.width + gap; ++x)\r
+        {\r
+            int y1 = roi.y - tl1.y + y;\r
+            int x1 = roi.x - tl1.x + x;\r
+            if (y1 >= 0 && x1 >= 0 && y1 < img1.rows && x1 < img1.cols)\r
+            {\r
+                subimg1.at<Point3f>(y + gap, x + gap) = img1.at<Point3f>(y1, x1);\r
+                submask1.at<uchar>(y + gap, x + gap) = mask1.at<uchar>(y1, x1);\r
+                subdx1.at<float>(y + gap, x + gap) = dx1.at<float>(y1, x1);\r
+                subdy1.at<float>(y + gap, x + gap) = dy1.at<float>(y1, x1);\r
+            }\r
+            else\r
+            {\r
+                subimg1.at<Point3f>(y + gap, x + gap) = Point3f(0, 0, 0);\r
+                submask1.at<uchar>(y + gap, x + gap) = 0;\r
+                subdx1.at<float>(y + gap, x + gap) = 0.f;\r
+                subdy1.at<float>(y + gap, x + gap) = 0.f;\r
+            }\r
+\r
+            int y2 = roi.y - tl2.y + y;\r
+            int x2 = roi.x - tl2.x + x;\r
+            if (y2 >= 0 && x2 >= 0 && y2 < img2.rows && x2 < img2.cols)\r
+            {\r
+                subimg2.at<Point3f>(y + gap, x + gap) = img2.at<Point3f>(y2, x2);\r
+                submask2.at<uchar>(y + gap, x + gap) = mask2.at<uchar>(y2, x2);\r
+                subdx2.at<float>(y + gap, x + gap) = dx2.at<float>(y2, x2);\r
+                subdy2.at<float>(y + gap, x + gap) = dy2.at<float>(y2, x2);\r
+            }\r
+            else\r
+            {\r
+                subimg2.at<Point3f>(y + gap, x + gap) = Point3f(0, 0, 0);\r
+                submask2.at<uchar>(y + gap, x + gap) = 0;\r
+                subdx2.at<float>(y + gap, x + gap) = 0.f;\r
+                subdy2.at<float>(y + gap, x + gap) = 0.f;\r
+            }\r
+        }\r
+    }\r
+    \r
+    Mat terminals, leftT, rightT, top, bottom;\r
+\r
+    switch (cost_type_)\r
+    {\r
+    case GraphCutSeamFinder::COST_COLOR:\r
+        setGraphWeightsColor(subimg1, subimg2, submask1, submask2, \r
+                             terminals, leftT, rightT, top, bottom);\r
+        break;\r
+    case GraphCutSeamFinder::COST_COLOR_GRAD:\r
+        setGraphWeightsColorGrad(subimg1, subimg2, subdx1, subdx2, subdy1, subdy2, \r
+                                 submask1, submask2, terminals, leftT, rightT, top, bottom);\r
+        break;\r
+    default:\r
+        CV_Error(CV_StsBadArg, "unsupported pixel similarity measure");\r
+    }\r
+\r
+    gpu::GpuMat terminals_d(terminals);\r
+    gpu::GpuMat leftT_d(leftT);\r
+    gpu::GpuMat rightT_d(rightT);\r
+    gpu::GpuMat top_d(top);\r
+    gpu::GpuMat bottom_d(bottom);\r
+    gpu::GpuMat labels_d, buf_d;\r
+\r
+    gpu::graphcut(terminals_d, leftT_d, rightT_d, top_d, bottom_d, labels_d, buf_d);\r
+\r
+    Mat_<uchar> labels = labels_d;\r
+    for (int y = 0; y < roi.height; ++y)\r
+    {\r
+        for (int x = 0; x < roi.width; ++x)\r
+        {\r
+            if (labels(y + gap, x + gap))\r
+            {\r
+                if (mask1.at<uchar>(roi.y - tl1.y + y, roi.x - tl1.x + x))\r
+                    mask2.at<uchar>(roi.y - tl2.y + y, roi.x - tl2.x + x) = 0;\r
+            }\r
+            else\r
+            {\r
+                if (mask2.at<uchar>(roi.y - tl2.y + y, roi.x - tl2.x + x))\r
+                    mask1.at<uchar>(roi.y - tl1.y + y, roi.x - tl1.x + x) = 0;\r
+            }\r
+        }\r
+    }\r
+}\r
+\r
+\r
+void GraphCutSeamFinderGpu::setGraphWeightsColor(const Mat &img1, const Mat &img2, const Mat &mask1, const Mat &mask2, \r
+                                                 Mat &terminals, Mat &leftT, Mat &rightT, Mat &top, Mat &bottom)\r
+{\r
+    const Size img_size = img1.size();\r
+\r
+    terminals.create(img_size, CV_32S);\r
+    leftT.create(Size(img_size.height, img_size.width), CV_32S);\r
+    rightT.create(Size(img_size.height, img_size.width), CV_32S);\r
+    top.create(img_size, CV_32S);\r
+    bottom.create(img_size, CV_32S);\r
+\r
+    Mat_<int> terminals_(terminals);\r
+    Mat_<int> leftT_(leftT);\r
+    Mat_<int> rightT_(rightT);\r
+    Mat_<int> top_(top);\r
+    Mat_<int> bottom_(bottom);\r
+\r
+    // Set terminal weights\r
+    for (int y = 0; y < img_size.height; ++y)\r
+    {\r
+        for (int x = 0; x < img_size.width; ++x)\r
+        {\r
+            float source = mask1.at<uchar>(y, x) ? terminal_cost_ : 0.f;\r
+            float sink = mask2.at<uchar>(y, x) ? terminal_cost_ : 0.f;\r
+            terminals_(y, x) = saturate_cast<int>((source - sink) * 255.f);\r
+        }\r
+    }\r
+\r
+    // Set regular edge weights\r
+    const float weight_eps = 1.f;\r
+    for (int y = 0; y < img_size.height; ++y)\r
+    {\r
+        for (int x = 0; x < img_size.width; ++x)\r
+        {\r
+            if (x > 0)\r
+            {\r
+                float weight = normL2(img1.at<Point3f>(y, x - 1), img2.at<Point3f>(y, x - 1)) +\r
+                               normL2(img1.at<Point3f>(y, x), img2.at<Point3f>(y, x)) +\r
+                               weight_eps;\r
+                if (!mask1.at<uchar>(y, x - 1) || !mask1.at<uchar>(y, x) ||\r
+                    !mask2.at<uchar>(y, x - 1) || !mask2.at<uchar>(y, x))\r
+                    weight += bad_region_penalty_;\r
+                leftT_(x, y) = saturate_cast<int>(weight * 255.f);\r
+            }\r
+            else\r
+                leftT_(x, y) = 0;\r
+\r
+            if (x < img_size.width - 1)\r
+            {\r
+                float weight = normL2(img1.at<Point3f>(y, x), img2.at<Point3f>(y, x)) +\r
+                               normL2(img1.at<Point3f>(y, x + 1), img2.at<Point3f>(y, x + 1)) +\r
+                               weight_eps;\r
+                if (!mask1.at<uchar>(y, x) || !mask1.at<uchar>(y, x + 1) ||\r
+                    !mask2.at<uchar>(y, x) || !mask2.at<uchar>(y, x + 1))\r
+                    weight += bad_region_penalty_;\r
+                rightT_(x, y) = saturate_cast<int>(weight * 255.f);\r
+            }\r
+            else\r
+                rightT_(x, y) = 0;\r
+\r
+            if (y > 0)\r
+            {\r
+                float weight = normL2(img1.at<Point3f>(y - 1, x), img2.at<Point3f>(y - 1, x)) +\r
+                               normL2(img1.at<Point3f>(y, x), img2.at<Point3f>(y, x)) +\r
+                               weight_eps;\r
+                if (!mask1.at<uchar>(y - 1, x) || !mask1.at<uchar>(y, x) ||\r
+                    !mask2.at<uchar>(y - 1, x) || !mask2.at<uchar>(y, x))\r
+                    weight += bad_region_penalty_;\r
+                top_(y, x) = saturate_cast<int>(weight * 255.f);\r
+            }\r
+            else\r
+                top_(y, x) = 0;\r
+\r
+            if (y < img_size.height - 1)\r
+            {\r
+                float weight = normL2(img1.at<Point3f>(y, x), img2.at<Point3f>(y, x)) +\r
+                               normL2(img1.at<Point3f>(y + 1, x), img2.at<Point3f>(y + 1, x)) +\r
+                               weight_eps;\r
+                if (!mask1.at<uchar>(y, x) || !mask1.at<uchar>(y + 1, x) ||\r
+                    !mask2.at<uchar>(y, x) || !mask2.at<uchar>(y + 1, x))\r
+                    weight += bad_region_penalty_;\r
+                bottom_(y, x) = saturate_cast<int>(weight * 255.f);\r
+            }\r
+            else\r
+                bottom_(y, x) = 0;\r
+        }\r
+    }\r
+}\r
+\r
+\r
+void GraphCutSeamFinderGpu::setGraphWeightsColorGrad(\r
+        const Mat &img1, const Mat &img2, const Mat &dx1, const Mat &dx2,\r
+        const Mat &dy1, const Mat &dy2, const Mat &mask1, const Mat &mask2, \r
+        Mat &terminals, Mat &leftT, Mat &rightT, Mat &top, Mat &bottom)\r
+{\r
+    const Size img_size = img1.size();\r
+\r
+    terminals.create(img_size, CV_32S);\r
+    leftT.create(Size(img_size.height, img_size.width), CV_32S);\r
+    rightT.create(Size(img_size.height, img_size.width), CV_32S);\r
+    top.create(img_size, CV_32S);\r
+    bottom.create(img_size, CV_32S);\r
+\r
+    Mat_<int> terminals_(terminals);\r
+    Mat_<int> leftT_(leftT);\r
+    Mat_<int> rightT_(rightT);\r
+    Mat_<int> top_(top);\r
+    Mat_<int> bottom_(bottom);\r
+\r
+    // Set terminal weights\r
+    for (int y = 0; y < img_size.height; ++y)\r
+    {\r
+        for (int x = 0; x < img_size.width; ++x)\r
+        {\r
+            float source = mask1.at<uchar>(y, x) ? terminal_cost_ : 0.f;\r
+            float sink = mask2.at<uchar>(y, x) ? terminal_cost_ : 0.f;\r
+            terminals_(y, x) = saturate_cast<int>((source - sink) * 255.f);\r
+        }\r
+    }\r
+\r
+    // Set regular edge weights\r
+    const float weight_eps = 1.f;\r
+    for (int y = 0; y < img_size.height; ++y)\r
+    {\r
+        for (int x = 0; x < img_size.width; ++x)\r
+        {\r
+            if (x > 0)\r
+            {\r
+                float grad = dx1.at<float>(y, x - 1) + dx1.at<float>(y, x) +\r
+                             dx2.at<float>(y, x - 1) + dx2.at<float>(y, x) + weight_eps;\r
+                float weight = (normL2(img1.at<Point3f>(y, x - 1), img2.at<Point3f>(y, x - 1)) +\r
+                                normL2(img1.at<Point3f>(y, x), img2.at<Point3f>(y, x))) / grad +\r
+                               weight_eps;\r
+                if (!mask1.at<uchar>(y, x - 1) || !mask1.at<uchar>(y, x) ||\r
+                    !mask2.at<uchar>(y, x - 1) || !mask2.at<uchar>(y, x))\r
+                    weight += bad_region_penalty_;\r
+                leftT_(x, y) = saturate_cast<int>(weight * 255.f);\r
+            }\r
+            else\r
+                leftT_(x, y) = 0;\r
+\r
+            if (x < img_size.width - 1)\r
+            {\r
+                float grad = dx1.at<float>(y, x) + dx1.at<float>(y, x + 1) +\r
+                             dx2.at<float>(y, x) + dx2.at<float>(y, x + 1) + weight_eps;\r
+                float weight = (normL2(img1.at<Point3f>(y, x), img2.at<Point3f>(y, x)) +\r
+                                normL2(img1.at<Point3f>(y, x + 1), img2.at<Point3f>(y, x + 1))) / grad +\r
+                               weight_eps;\r
+                if (!mask1.at<uchar>(y, x) || !mask1.at<uchar>(y, x + 1) ||\r
+                    !mask2.at<uchar>(y, x) || !mask2.at<uchar>(y, x + 1))\r
+                    weight += bad_region_penalty_;\r
+                rightT_(x, y) = saturate_cast<int>(weight * 255.f);\r
+            }\r
+            else\r
+                rightT_(x, y) = 0;\r
+\r
+            if (y > 0)\r
+            {\r
+                float grad = dy1.at<float>(y - 1, x) + dy1.at<float>(y, x) +\r
+                             dy2.at<float>(y - 1, x) + dy2.at<float>(y, x) + weight_eps;\r
+                float weight = (normL2(img1.at<Point3f>(y - 1, x), img2.at<Point3f>(y - 1, x)) +\r
+                                normL2(img1.at<Point3f>(y, x), img2.at<Point3f>(y, x))) / grad +\r
+                               weight_eps;\r
+                if (!mask1.at<uchar>(y - 1, x) || !mask1.at<uchar>(y, x) ||\r
+                    !mask2.at<uchar>(y - 1, x) || !mask2.at<uchar>(y, x))\r
+                    weight += bad_region_penalty_;\r
+                top_(y, x) = saturate_cast<int>(weight * 255.f);\r
+            }\r
+            else\r
+                top_(y, x) = 0;\r
+\r
+            if (y < img_size.height - 1)\r
+            {\r
+                float grad = dy1.at<float>(y, x) + dy1.at<float>(y + 1, x) +\r
+                             dy2.at<float>(y, x) + dy2.at<float>(y + 1, x) + weight_eps;\r
+                float weight = (normL2(img1.at<Point3f>(y, x), img2.at<Point3f>(y, x)) +\r
+                                normL2(img1.at<Point3f>(y + 1, x), img2.at<Point3f>(y + 1, x))) / grad +\r
+                               weight_eps;\r
+                if (!mask1.at<uchar>(y, x) || !mask1.at<uchar>(y + 1, x) ||\r
+                    !mask2.at<uchar>(y, x) || !mask2.at<uchar>(y + 1, x))\r
+                    weight += bad_region_penalty_;\r
+                bottom_(y, x) = saturate_cast<int>(weight * 255.f);\r
+            }\r
+            else\r
+                bottom_(y, x) = 0;\r
+        }\r
+    }\r
+}\r
+#endif\r
+\r
 } // namespace detail\r
 } // namespace cv\r
 \r
index fd45f07..e946ef1 100644 (file)
@@ -63,16 +63,17 @@ Stitcher Stitcher::createDefault(bool try_use_gpu)
     {
         stitcher.setFeaturesFinder(new detail::SurfFeaturesFinderGpu());
         stitcher.setWarper(new SphericalWarperGpu());
+        stitcher.setSeamFinder(new detail::GraphCutSeamFinderGpu());
     }
     else
 #endif
     {
         stitcher.setFeaturesFinder(new detail::SurfFeaturesFinder());
         stitcher.setWarper(new SphericalWarper());
+        stitcher.setSeamFinder(new detail::GraphCutSeamFinder());
     }
 
     stitcher.setExposureCompenstor(new detail::BlocksGainCompensator());
-    stitcher.setSeamFinder(new detail::GraphCutSeamFinder());
     stitcher.setBlender(new detail::MultiBandBlender(try_use_gpu));
 
     return stitcher;
index 7016155..e253d37 100644 (file)
@@ -132,7 +132,7 @@ std::string save_graph_to;
 string warp_type = "spherical";
 int expos_comp_type = ExposureCompensator::GAIN_BLOCKS;
 float match_conf = 0.65f;
-int seam_find_type = SeamFinder::GC_COLOR;
+string seam_find_type = "gc_color";
 int blend_type = Blender::MULTI_BAND;
 float blend_strength = 5;
 string result_name = "result.jpg";
@@ -262,14 +262,11 @@ int parseCmdArgs(int argc, char** argv)
         }
         else if (string(argv[i]) == "--seam")
         {
-            if (string(argv[i + 1]) == "no")
-                seam_find_type = SeamFinder::NO;
-            else if (string(argv[i + 1]) == "voronoi")
-                seam_find_type = SeamFinder::VORONOI;
-            else if (string(argv[i + 1]) == "gc_color")
-                seam_find_type = SeamFinder::GC_COLOR;
-            else if (string(argv[i + 1]) == "gc_colorgrad")
-                seam_find_type = SeamFinder::GC_COLOR_GRAD;
+            if (string(argv[i + 1]) == "no" ||
+                string(argv[i + 1]) == "voronoi" ||
+                string(argv[i + 1]) == "gc_color" ||
+                string(argv[i + 1]) == "gc_colorgrad")
+                seam_find_type = argv[i + 1];
             else
             {
                 cout << "Bad seam finding method\n";
@@ -550,7 +547,35 @@ int main(int argc, char* argv[])
     Ptr<ExposureCompensator> compensator = ExposureCompensator::createDefault(expos_comp_type);
     compensator->feed(corners, images_warped, masks_warped);
 
-    Ptr<SeamFinder> seam_finder = SeamFinder::createDefault(seam_find_type);
+    Ptr<SeamFinder> seam_finder;
+    if (seam_find_type == "no")\r
+        seam_finder = new detail::NoSeamFinder();\r
+    else if (seam_find_type == "voronoi")\r
+        seam_finder = new detail::VoronoiSeamFinder();\r
+    else if (seam_find_type == "gc_color")\r
+    {\r
+#ifndef ANDROID\r
+        if (try_gpu)\r
+            seam_finder = new detail::GraphCutSeamFinderGpu(GraphCutSeamFinderBase::COST_COLOR);\r
+        else\r
+#endif\r
+            seam_finder = new detail::GraphCutSeamFinder(GraphCutSeamFinderBase::COST_COLOR);\r
+    }\r
+    else if (seam_find_type == "gc_colorgrad")\r
+    {\r
+#ifndef ANDROID\r
+        if (try_gpu)\r
+            seam_finder = new detail::GraphCutSeamFinderGpu(GraphCutSeamFinderBase::COST_COLOR_GRAD);\r
+        else\r
+#endif\r
+            seam_finder = new detail::GraphCutSeamFinder(GraphCutSeamFinderBase::COST_COLOR_GRAD);\r
+    }
+    if (seam_finder.empty())
+    {
+        cout << "Can't create the following seam finder '" << seam_find_type << "'\n";
+        return 1;
+    }
+
     seam_finder->find(images_warped_f, corners, masks_warped);
 
     // Release unused memory