Opencv convex Hull (convex bag)

Source: Internet
Author: User
Tags scalar

#include <iostream>
#include <opencv2/opencv.hpp>

using namespace Std;
using namespace CV;

Mat img1, Img2, IMG3, Img4, Img_result, Img_gray1, Img_gray2, Img_gray3, img_canny1;

Char win1[] = "Window1";
Char win2[] = "Window2";
Char win3[] = "WINDOW3";
Char win4[] = "WINDOW4";
Char win5[] = "WINDOW5";

int thread_value = 100;
int max_value = 255;
RNG rng1 (12345);

int Demo_convex_hull ();
void Demo_1 (int, void*);

Discover Convex hull
int Demo_convex_hull ()
{
Namedwindow (Win1, cv_window_autosize);
Namedwindow (win2, cv_window_autosize);
Namedwindow (Win3, cv_window_autosize);

IMG1 = Imread ("d://images//1//temp2.jpg");
Img2 = Imread ("d://images//1//p5_1.jpg");
if (Img1.empty ())
{
cout << "Could not load image ..." << Endl;
return 0;
}

Imshow (Win1, IMG1);
IMG4 = Mat::zeros (Img1.size (), CV_8UC3);

Turn Gray Chart
Cvtcolor (IMG1, Img_gray1, Cv_bgr2gray);
Blur processing
Blur (Img_gray1, Img2, Size (3, 3), point ( -1,-1), border_default);

Createtrackbar ("track", Win1, &thread_value, Max_value, demo_1);
Demo_1 (0,0);

return 0;
}

void Demo_1 (int,void*)
{
Vector<vector<point>> vec_p;
Vector<vec4i> vec_4i;

Threshold (Img2, IMG3, Thread_value, Max_value, thresh_binary);
Findcontours (IMG3, vec_p, vec_4i, Retr_tree, Chain_approx_simple, point (0, 0));

Vector<vector<point>> Convexs (Vec_p.size ());
For (size_t i=0;i<vec_p.size (); i++)
{
Convexhull (Vec_p[i], convexs[i], false, true);
}

For (size_t j=0;j<vec_p.size (); j + +)
{
Scalar color_1 = scalar (rng1.uniform (0,255), rng1.uniform (0, 255), Rng1.uniform (0, 255));
Drawcontours (Img4, Vec_p, J, color_1, 2, Line_8, vec_4i, 0, point (0, 0));
Drawcontours (Img4, Convexs, J, color_1, 2, Line_8, vec_4i, 0, point (0, 0));
}
Imshow (WIN2,IMG4);
}

int main ()
{
Demo_convex_hull ();

Waitkey (0);
return 0;
}

Opencv convex Hull (convex bag)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.