conceptbmのブログ -8ページ目

conceptbmのブログ

ブログの説明を入力します。

Based on image analysis of the key elements is to extract features in an image representative, and the lines, contours, block often is the best embodies the characteristics of several elements, the article on against in these important image features, research their use in OpenCV, Air Jordan Outlet and do some simple basic application. A, Canny detected contour on the article mentioned sobel edge detection, and rewrite the C ++ code that allowed soble consistent with matlab algorithm effect, while soble Nike Free TR Fit edge detection is Nike Air Max 2015 Women based on a single threshold, we can not take into account the 2015 Nike KD 7 Kids Basketball Shoes Sport Turq Charcoal Atomic Green Outlet low These two issues rich edge deletion and edge high threshold threshold value. The canny operator is well up for this shortfall, from the current view, canny edge detection in image contour extraction of doing is the best edge detection algorithm. canny edge detection using dual-threshold value method, the high threshold for detecting image is important, significant lines, contours, etc., and the low threshold to ensure that no loss of detail parts, low threshold detected edge richer, but many edges and not our concern. Finally, a search algorithm, the low threshold value and a high threshold of edge lines overlap reservations, other lines are deleted. Algorithm principle of this article does not canny further instructions will Mens Nike Free 3.0 Wool Skin Shoes Blue Yellow be detailed later in the image processing algorithm related articles. Here we use OpenCV function to detect the Canny edge Mens Nike Free 3.0 V2 Shoes White Black Red int main () {Mat I = imread (\u0026 quot; ../ cat.png \u0026 quot;); cvtColor (I, I, CV_BGR2GRAY); Mat contours; Canny (I, contours , 125,350); threshold (contours, contours, 128,255, THRESH_BINARY); namedWindow (\u0026 quot; Canny \u0026 quot;); imshow (\u0026 quot; Canny \u0026 quot;, contours); waitKey (); return 0;} display as follows: Second, straight line detection frequency of occurrence in the image is very high, and straight as a feature of the image elements of the image analysis has a very important role in this paper to detect the image line by OpenCV in hough transform. We look at the most basic Hough transform function HoughLines, its prototype is as follows: void HoughLines (InputArray image, OutputArray lines, double rho, double theta, int threshold, double srn = 0, double stn = 0); its input is a outline binary image, often as a result of image edge detection obtained; its output is an array containing multiple Vec2f points, each element of the array is a binary floating-point data to \u0026 lt; rou, theta \u0026 gt;, rou Representative straight-line distance from the origin of coordinates, theta angle representatives. 3 and 4 parameter represents the steps, because Hough transform is actually an exhaustive algorithm, rho represents the step distance, theta angle representatives of steps. The first five parameter is to set a minimum voting threshold number directly, know Hough principle, this argument should be easy to understand. From the output of this function, we can see, to get straight and not specified in the image of the starting point and end point, you need to calculate our own, if we want to be displayed directly in the image will be more trouble, and there will be In many ways close to a straight line, in fact, they are repeated, in order to solve the above problems, OpenCV and provides a function HoughLinesP (). Its output is a Vector of Vec4i. Vector each element represents a straight line, is composed of a group consisting of 4 yuan float, a group of the first two points, two points after a group of straight lines in the image represents the start and end points. void HoughLinesP (InputArray image, OutputArray lines, double rho, double theta, int threshold, double minLineLength = 0, double maxLineGap = 0); explain the last two parameters, minLineLength specifies the minimum width of the line detection, if less than the minimum the Nike Hyperdunk 2014 width of the discard, maxLineGap specified by the straight line at the same point, if the distance is less than maxLineGap will be merged. Here is an example HoughLinesP line detection: int main () {Mat image = imread (\u0026 quot; ../ car.png \u0026 quot;); Mat I; cvtColor (image, I, CV_BGR2GRAY); Mat contours; Canny (I, contours, 125,350); threshold (contours, contours, 128,255, THRESH_BINARY); Mens Nike Free 3.0 V2 Shoes White Black Red vector \u0026 lt; Vec4i \u0026 gt; lines; // line detection, the minimum vote of 90 lines not less than 50, the gap is not less than 10 HoughLinesP (contours, lines, 1, CV_PI / 180,80,50,10); drawDetectLines (image, lines, Scalar (0,255,0)); namedWindow (\u0026 quot; Lines \u0026 quot;); imshow (\u0026 quot; Lines \u0026 quot;, image); waitKey (); return 0; } The above program will detect the lines stored in the lines variable, we need to further draw them on the image: void drawDetectLines (Mat \u0026 amp; image, const vector \u0026 lt; Vec4i \u0026 gt; \u0026 amp; lines, Scalar \u0026 amp; color) {// will detect to draw a straight line on the chart out vector \u0026 lt; Vec4i \u0026 gt; :: const_iterator it = lines.begin Nike Air Zoom Flight The Glove (); while (! it = lines.end ()) {Point pt1 ((* it) [0], (* it) [1]); Point pt2 ((* it) [2], (* it) [3]); line (image, pt1, pt2, color, 2); // line width is set to 2 ++ it;} } actually Hough transform can detect a lot of fixed shape, such as: round, square and so on. They are basically the same principle, is to construct a matrix 2015 Nike Free 5.0 vote. OpenCV in the circle detection function provides HoughCircles, its output is a Vector of each element Vec3i, Vector contains three floats, the former two are the coordinates of the center of the circle, the last one is the radius. Third, contour extraction and described in Target Recognition should interest us first goal is extracted, and the general common steps are extracted by color or texture target prospects graph (a black and white image, the target is displayed in white image), then we have to analyze Nike Air Max the prospects of FIG further target extracted, and here is often used to extract the target profile. OpenCV function to extract the object contour is findContours, its input image is a binary image, the output is a set of contour points of each connected region: vector \u0026 lt; vector \u0026 lt; Point \u0026 gt; \u0026 gt ;. The size outer vector represents the number of image contour, which represents the number of vector of size on the contour points. Here we look at the usage of function by way of example. int main () {using namespace cv; Mat image = imread (\u0026 quot; ../ shape.png \u0026 quot;); cvtColor (image, image, CV_BGR2GRAY); vector \u0026 lt; vector \u0026 lt; Point \u0026 gt; \u0026 gt; contours; // find findContours (image , contours, CV_RETR_EXTERNAL, CV_CHAIN_APPROX_NONE); // draw Mat result (image.size (), CV_8U, Scalar (0)); drawContours (result, contours, -1, Scalar (255), 2); namedWindow (\u0026 quot; contours \u0026 quot ;); imshow (\u0026 quot; contours \u0026 quot;, result); waitKey (); return 0;} The above program contains two functions, the first one is to find the outline of the function, its third argument the instructions to locate the type of contour, Here we use the outer contour, you can also find all the contours, which includes a number of holes in the part, like the outline of an image forming figures arms and waist. Chapter 4 describes the method of contour parameter representation, the parameters of the program outline includes a description of all the points, other parameters can also be used to make the place a little straight, save only the start and end point of the line positions, the specific parameter usage can refer to the manual introduced in the function. The second function is a painting drawContours contour function, its first three parameter program setting of -1 indicates that all the contours are drawn, you can also specify the number you want to draw the outline. After extracting the outline, in fact, we are more concerned about is if these features can be converted to use contour, which is related to the description of the problem outline, then there is a variety of methods to choose from, such as the vector into polygons, rectangles, ellipses Wait. OpenCV provides in some of these functions. // Contour is represented as a rectangle Air Max 2011 Womens Grey Green Black Rect r = boundingRect (Mat (contours [0])); rectangle (result, r, Scalar (255), 2); // contour is represented as a circle float radius; Point2f center; minEnclosingCircle ( Mat (contours [1]), center, radius); circle (result, Point (center), static_cast \u0026 lt; int \u0026 gt; (radius), Scalar (255), 2); // contour is represented as a polygon vector \u0026 lt; Point \u0026 gt; poly Air Max 2011 Womens Grey Green Black ; approxPolyDP (Mat (contours [2]), poly, 5, true); vector \u0026 lt; Point 2015 Nike KD 7 Kids Basketball Shoes Sport Turq Charcoal Atomic Green Outlet \u0026 gt; :: const_iterator itp = poly.begin (); while (! itp = (poly.end () - 1)) {line (result, * itp, * (itp + 1), Scalar (255), 2); ++ itp;} line (result, * itp, * (poly.begin ()), Scalar (255), 2); // contour is represented as a convex polygon vector \u0026 lt; Point \u0026 gt; hull; convexHull (Mat (contours [3]), hull); vector \u0026 lt; Point \u0026 gt; :: const_iterator ith = hull.begin ();! while (ith = (hull.end () - 1)) {line (result, * ith, * (ith + 1), Scalar (255), 2); ++ ith;} line (result, * ith, * (hull.begin ()), Scalar (255), 2); the program we turn draw rectangles, circles, polygons and convex polygons. Final results are as follows: for communicating area analysis this is far from over, we can further calculate other attributes of each connected region, such as: gravity, central moments and other features, these Mens Nike Free 3.0 V2 Shoes White Black Red elements have the opportunity to start to write. The following functions can try: minAreaRect: computing a minimal area circumscribed rectangle, contourArea can be calculated within the contour area of ​​the communication area; pointPolygenTest can be used to determine whether a point is inside a polygon. mathShapes can compare the similarity of two shapes, a very useful function.OpenCV growth path (8): straight, contour extraction and description