Convex Hull

X is a bounded subset of the plane, the convex hull may be visualized as the shape formed by a rubber band stretched around X.
The convex hull of a set X of points in the Euclidean plane is the smallest convex set that contains X. when
Formally, the convex hull may be defined as the intersection of all convex sets containing X or as the set of all convex combinations of points in X.
A set of points is defined to be convex if it contains the line segments connecting each pair of its points. The convex hull of a given set X may be defined as
  1. The (unique) minimal convex set containing X
  2. The intersection of all convex sets containing X
  3. The set of all convex combinations of points in X.

void convexHull(InputArray points, OutputArray hull, bool clockwise=false, bool returnPoints=true )

Parameters:
  • points – Input 2D point set, stored in std::vector or Mat.
  • hull – Output convex hull. It is either an integer vector of indices or vector of points. In the first case, the hull elements are 0-based indices of the convex hull points in the original array (since the set of convex hull points is a subset of the original point set). In the second case, hull elements are the convex hull points themselves.
  • hull_storage – Output memory storage in the old API (cvConvexHull2 returns a sequence containing the convex hull points or their indices).
  • clockwise – Orientation flag. If it is true, the output convex hull is oriented clockwise. Otherwise, it is oriented counter-clockwise. The assumed coordinate system has its X axis pointing to the right, and its Y axis pointing upwards.
  • orientation – Convex hull orientation parameter in the old API, CV_CLOCKWISE or CV_COUNTERCLOCKWISE.
  • returnPoints – Operation flag. In case of a matrix, when the flag is true, the function returns convex hull points. Otherwise, it returns indices of the convex hull points. When the output array is std::vector, the flag is ignored, and the output depends on the type of the vector: std::vector<int> implies returnPoints=true, std::vector<Point> implies returnPoints=false.
A good example for Convex Hull implementation is provided in OpenCV Documentation. Below code is a modification of the same.

Example:

------------
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include <iostream>
#include <stdio.h>
#include <stdlib.h>

using namespace cv;
using namespace std;

int main( int argc, char** argv )
{
 Mat src; Mat src_gray;
 src = imread( "airplane1.jpg", 1 );
 resize(src, src, Size(640,480), 0, 0, INTER_CUBIC);
 cvtColor( src, src_gray, CV_BGR2GRAY );
 blur( src_gray, src_gray, Size(3,3) ); 
 namedWindow( "Source", CV_WINDOW_AUTOSIZE );
 imshow( "Source", src );

 

 // Convex Hull implementation
 Mat src_copy = src.clone();
 Mat threshold_output;
 vector<vector<Point> > contours;
 vector<Vec4i> hierarchy;

 // Find contours
 threshold( src_gray, threshold_output, 200, 255, THRESH_BINARY );
 findContours( threshold_output, contours, hierarchy, CV_RETR_TREE, CV_CHAIN_APPROX_SIMPLE, Point(0, 0) );

 // Find the convex hull object for each contour
 vector<vector<Point> >hull( contours.size() );
 for( int i = 0; i < contours.size(); i++ )
 {  convexHull( Mat(contours[i]), hull[i], false ); }

 // Draw contours + hull results
 RNG rng;
 Mat drawing = Mat::zeros( threshold_output.size(), CV_8UC3 );
 for( int i = 0; i< contours.size(); i++ )
 {
  Scalar color = Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
  drawContours( drawing, contours, i, color, 1, 8, vector<Vec4i>(), 0, Point() );
  drawContours( drawing, hull, i, color, 1, 8, vector<Vec4i>(), 0, Point() );
 }

 // Show in a window
 namedWindow( "Hull demo", CV_WINDOW_AUTOSIZE );
 imshow( "Hull demo", drawing );

 waitKey(0);
 return(0);
}
------------

Result:

Sources:
http://en.wikipedia.org/wiki/Convex_hull

8 comments:


  1. حشرات
    النمل الابيض
    التخلص من النمل
    ابادة حشرات
    يصعب على الأفراد مؤسسة مكافحة البق بمهد الذهب كسائر الحشرات داخل البيت و بالأساليب العادية حيث أن البق كما قد سلف ذكره تسكن في المفروشات و العائلة و من ثم يصعب بخ المبيدات على أماكن السبات لهذا اذا وجدت حشرة البق تسكن منزلك فعليك التواصل بنا ليتم مكافحتها بواسطة شركتنا بأحدث الأساليب فنحن لدينا أجدد تقنيات مؤسسة مكافحة البق بمهد الذهب و الحشرات بالأجهزة و المعدات التي يسهل عليها الوصول لأضيق الأماكن دون الاحتياج لنقل الأثاث لموضع أخر أو تفريغ القاعات كما أننا نعتمد في مؤسسة مكافحة البق بمهد الذهب تحديدا و بقية الحشرات على مواد كيميائية تقضي على الحشرات دون الحاق الضرر بالإنسان أو الحيوان فأنت لست بحاجة الى مغادرة مقر البخ و حتى الناشئين و الكهول و السقماء لن تضرهم المواد التي نستخدمها و التي تعتبر ايضاً صديقة للبيئة فقد حرصنا كل الحرص على سلامتك وسلامة أسرتك في جودة خامات مؤسسة مكافحة البق بمهد الذهب و الحشرات.


    مؤسسة مكافحة الذباب بمهد الذهب
    تعتبر شركتنا من أفضَل و كابر مؤسسات بخ المبيدات في الشرق الأوسط حيث أننا نتميز عن باقى مؤسسات بخ المبيدات بادخار الكثير من الخدمات المهمة ونقوم ببخ المبيدات المنزلية و مكافحة جميع أشكال الحشرات الطائرة كالذباب و البعوض و غيرها و الحشرات الزاحفة مثل النمل و الصراصير و العديد من الحشرات الأخرى كما أننا نتميز بالعديد من المميزات التي سوف نعددها لك لاحقا.

    ReplyDelete
  2. تختفي هذه الكائنات في النهار وتنشط بالليل بحثاً عن طعامها، ولها القدرة على الرؤية بالضوء الخافت، كما أنّ لديها أصابع سميكة ذات ملمس لزج تساعدها على الالتصاق بالجدران، مما يسبب الإزعاج لدى ربات المنزل، ومن الممكن التخلص منها بالعديد من الطرق الطبيعية والسهلة، وهذا ما سنعرفكم عليه في هذا المقال.

    شركة رش مبيدات بحائل
    شركة رش مبيدات بالاحساء
    شركة رش مبيدات ببريدة
    شركة رش مبيدات بابها

    ReplyDelete
  3. AVG Retail is the best Antivirus programming which is accessible on avg.com/retail , gives the total suite of highlights which can avg.com/retail verify your computerized on the web and disconnected work of the framework or gadgets.

    ReplyDelete
  4. فصل تيار التكييف بشكل نهائي عن المكيف
    يتم العمل على ابعاد أشجار أو عشب بعيدًا عن جسم مكيف الهواء لمسافة 60 مترًا على الأقل.بعد التأكد من فصل التيار ، استخدم مفك براغي لإزالة المحرك الداخلي لمكيف الهواء.

    يتم العمل على إزالة الجزء العلوي من التكييف مع الحرص على عدم تحريك أو إتلاف أي سلوك حتى لا تتسبب في أي خلل في التكييف.

    إذا كان من السهل فك وتركيب المروحة ، غسيل المكيف الشباك في مكانه يمكنك أيضًا إزالتها لتجنب تلف المحرك.

    اقرا المزيد على شركة ركن البستان للخدمات المنزلية

    ReplyDelete
  5. Thanks to the owner of this site who really shares this great work of this site. thanks for sharing. It often happens that the camera stops working in gotomeeting. So all you have to do is go to this link how to allow gotomeeting access camera on windows and find a solution.

    ReplyDelete
  6. Thanks for sharing information on this upload. How did you get this information? Your website is very well designed, and I have read a few articles on it. I appreciate your efforts and encourage you to keep going. You may be interested in How fast you hit the spacebar key the latest article. Learn more about microphones here when you get started. See the article spacebar counter to learn more.

    ReplyDelete