Ask Your Question

Revision history [back]

i tried some simple code and get this image

image description

#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include <iostream>

using namespace std;
using namespace cv;

int main(int argc, char* argv[])

{
    Mat image, gray,dst_img;
    String image_file_name = "15035807843241733.jpg";//argv[1];

        image = imread(image_file_name);
        if (image.empty())
        {
            cout << "\nunable to open " << image_file_name << "\nprogram terminated!\n";
            return 1;
        }

    imshow("source", image);

    cvtColor(image, gray, COLOR_BGR2GRAY);
    Canny(gray, dst_img, 50, 150);
    blur(dst_img, dst_img, Size(5, 5));
    threshold(dst_img, dst_img, 0, 255, THRESH_OTSU);

    vector<Point> pts;
    vector<Point> hull;
    findNonZero(dst_img, pts);
    convexHull(pts, hull, true);
    polylines(image, hull, true, Scalar(0, 0, 255), 2);

    imshow("dest", image);
    waitKey();

    return 0;
}

i tried some simple code and get this image

image description

#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include <iostream>

using namespace std;
using namespace cv;

int main(int argc, char* argv[])

{
    Mat image, gray,dst_img;
    String image_file_name = "15035807843241733.jpg";//argv[1];

        image = imread(image_file_name);
        if (image.empty())
        {
            cout << "\nunable to open " << image_file_name << "\nprogram terminated!\n";
            return 1;
        }

    imshow("source", image);

    cvtColor(image, gray, COLOR_BGR2GRAY);
    Canny(gray, dst_img, 50, 150);
    blur(dst_img, dst_img, Size(5, 5));
    threshold(dst_img, dst_img, 0, 255, THRESH_OTSU);

    vector<Point> pts;
    vector<Point> hull;
    findNonZero(dst_img, pts);
    convexHull(pts, hull, true);
    polylines(image, hull, true, Scalar(0, 0, 255), 2);

    imshow("dest", image);
    waitKey();

    return 0;
}

another test image and result:

image description ....image description

i tried some simple code and get this image

image description

another test image and result:

image description ....image description

#include "opencv2/highgui.hpp"
#include "opencv2/imgproc.hpp"
#include <iostream>

using namespace std;
using namespace cv;

int main(int argc, char* argv[])

{
    Mat image, gray,dst_img;
    String image_file_name = "15035807843241733.jpg";//argv[1];

        image = imread(image_file_name);
        if (image.empty())
        {
            cout << "\nunable to open " << image_file_name << "\nprogram terminated!\n";
            return 1;
        }

    imshow("source", image);

    cvtColor(image, gray, COLOR_BGR2GRAY);
    Canny(gray, dst_img, 50, 150);
    blur(dst_img, dst_img, Size(5, 5));
    threshold(dst_img, dst_img, 0, 255, THRESH_OTSU);

    vector<Point> pts;
    vector<Point> hull;
    findNonZero(dst_img, pts);
    convexHull(pts, hull, true);
    polylines(image, hull, true, Scalar(0, 0, 255), 2);

    imshow("dest", image);
    waitKey();

    return 0;
}

another test image and result:

image description ....image description