Seeking the shortest path of the picture 2 Detailed explanation of the Dijkstra algorithm Eric


CvMemStorage *storage=cvCreateMemStorage(block_size);
Use to create a memory memory to uniformly manage the memory of various dynamic objects.


function returns a newly created memory memory pointer.


parameter block_size corresponds to the size of each memory block in the memory device, and the default size of the memory block is 64K.
extern int strcmp(const char *s1,const char * s2);
When S1 <s2, return to the negative number is not -1
When S1 == S2, the return value = 0
When S1> S2, return to the positive number is not 1
Retrieves the contour from the dual -value image and returns the number of outline detected. The value of the first_contour is returned by the function, and its value will be the first outer contour
, null when the outline was detected. Other outlines can be connected to H_next and v_next to reach the first_contour.

int cvFindContours(          CvArr* image,      CvMemStorage* storage,       CvSeq** first_contour,
                                            int header_size=sizeof(CvContour),              int mode=CV_RETR_LIST,
                                            int method=CV_CHAIN_APPROX_SIMPLE,        CvPoint offset=cvPoint(0,0)          );
8 BitSingle -channel source dual -value image. Non -zero pixels are treated as 1, 0 pixel preservation remains unchanged. From a
gray image
The function of the second -value image is:
Return to container.
output parameters are used to store the first external contour.
The size of the sequence of the sequence. If you select the method = cv_chain_code, the header_size> = sizeof (cvchain);


header_size >= sizeof(CvContour)。
retrieval mode can be taken as follows:
cv_retr_external: only retrieve the outermost contour;
cv_retr_list: retrieve all outlines and put them in list;
cv_retr_ccomp: Retrieve all outlines and organize them into two layers: the top layer is the external boundary of each part, and the second layer is the empty boundary;
cv_retr_tree: Retrieve all outlines and reconstruct the entire level of nested outline.
blue indicates v_next, green represents h_next
Edge approximation method (except that CV_RETR_RUNS uses built -in approximation, other modes use the approximate algorithm of this setting). The value can be taken as follows:
cv_chain_code: with freeman
chain code

method outputs outline, and all other methods output polygon (sequence of the vertex).

cv_chain_approx_none: Convert all the consecutive codes into points.
cv_chain_approx_simple: The compressed level, vertical, and oblique parts, that is, the function only retains their end point.
cv_chain_approx_tc89_L1, CV_Chain_APPROX_TC89_KCOS: Use The Flavors of Teh-Chin Chain

One of

CV_LINK_RUNS: By connecting the horizontal segment 1, use a completely different edge extraction algorithm. This method can be used using the CV_RETR_LIST search mode.
, used to move all outline points. When the contour is from

ROI extraction and need to be analyzed in the entire image. This parameter will be useful.

CVDRAWCONTORS inimageDraw external and internal contour on the inside. When Thickness> = 0, draw the contour line; otherwise the part surrounded by the contour is filled.
void cvDrawContours(     CvArr *img,           CvSeq* contour,
                                                 CvScalar external_color,       CvScalar hole_color,
                                                 int max_level,            int thickness=1,
                                                 int line_type=8,         CvPoint offset=cvPoint(0,0)   );
The image of the contour is drawn on it. As in other drawing functions, the contour is the pruning result of ROI.
point to the first outlinepointer
outer contour color.
Inner contour color.
Draw the maximum number of outlines. If it is 0, only draw Contour; if it is 1, all outlines of the same layer as Contour will be drawn; if it is 2, all the same layer and low -layer outlines after drawing are drawn, and so on; if the value is negative value, the value is negative value. The function does not draw the contour after the contour is drawn, but it will draw the subtitle until the ABS (MAX_LEVEL) -1 layer.
Draw the width of the contour line. If it is negative (for example, equal to cv_filled), the contour will be drawn inside.

The type of

contour segment, specifically check the description of CVLINE.
Move all points at the given value to all points
Example results:

#include “cv.h”
#include “cxcore.h”
#include “highgui.h”
int main( int argc, char** argv )

// State the iPLIMAGE pointer
  IplImage* pImg = NULL;
  IplImage* pContourImg = NULL;
CVMEMSTORAGE * Storage = cvcreateMemstorage (0); // Create memory block size is 64K
  CvSeq * contour = 0;
 int mode = CV_RETR_EXTERNAL;

if( argc == 3)
    if(strcmp(argv[2], “all”) == 0)
mode = cv_retr_ccomp; // Internal and external outlines are detected
// Create a window
  cvNamedWindow(“src”, 1);
// Load the image and force the transformation to Gray
 if( (pImg = cvLoadImage( “E:\\Lena.jpg”, 0)) != 0 )

      cvShowImage( “src”, pImg );
// For the outline display image application space

// 3 channel images in order to display in color
      pContourImg = cvCreateImage(cvGetSize(pImg),IPL_DEPTH_8U,3);
// Copy the original image and convert it to BGR image
      cvCvtColor(pImg, pContourImg, CV_GRAY2BGR);
// Find Contour
      cvFindContours( pImg, storage, &contour, sizeof(CvContour),
    mode, CV_CHAIN_APPROX_SIMPLE, cvPoint(0,0));

// Destruction window
      cvDestroyWindow( “src” );
      cvDestroyWindow( “contour” );
      return -1;
// Draw out outline
CVDRAWCONTOURS (PContourimg, Contour, // The former is an image, the latter is a pointer pointed to the first outline
CV_RGB (0,0,255), CV_RGB (255, 0, 0), // outer contour blue, inner contour red
2, 2, 8, CVPOINT (0,0)); // All the same layer and low -level outline after drawing contour, so on, the line width is 2, the line segment type is 8, the offset coordinates are (the offset coordinates ( 0, 0)
// Display images
  cvShowImage( “contour”, pContourImg );
// Destruction window
  cvDestroyWindow( “src” );
  cvDestroyWindow( “contour” );
// Release images
  cvReleaseImage( &pImg );
  cvReleaseImage( &pContourImg );
  return 0;


Related Posts

Spring-IOC container-Keke Teacher

Sixteen Week OJ Project D: Poinage leading odd number factor

zabbix email alarm

ubuntu20.04 Virtual environment creation and use Ubuntu20.04 to create a virtual development environment

Seeking the shortest path of the picture 2 Detailed explanation of the Dijkstra algorithm Eric

Random Posts

OPENCV training classifier Make XML document

R language DPLYR package: high -efficiency data processing function (Filter, Groupby, Mutate, Summarise)

jumpserver docker-compose deployment file yunson

linux driver-symbol export Monkey

Caption that Java thread is necessary for dead locks