for( i = 0; i < 8; i++ )
{
- reader->deltas[i][0] = (char) icvCodeDeltas[i].x;
- reader->deltas[i][1] = (char) icvCodeDeltas[i].y;
+ reader->deltas[i][0] = (schar) icvCodeDeltas[i].x;
+ reader->deltas[i][1] = (schar) icvCodeDeltas[i].y;
}
__END__;
CV_IMPL CvPoint
cvReadChainPoint( CvChainPtReader * reader )
{
- char *ptr;
+ schar *ptr;
int code;
CvPoint pt = { 0, 0 };
CV_ERROR( CV_StsNullPtr, "" );
pt = reader->pt;
-
+
ptr = reader->ptr;
if( ptr )
{
}
reader->ptr = ptr;
- reader->code = (char)code;
+ reader->code = (schar)code;
assert( (code & ~7) == 0 );
reader->pt.x = pt.x + icvCodeDeltas[code].x;
reader->pt.y = pt.y + icvCodeDeltas[code].y;
CvMemStoragePos initial_pos; /* starting storage pos */
CvMemStoragePos backup_pos; /* beginning of the latest approx. contour */
CvMemStoragePos backup_pos2; /* ending of the latest approx. contour */
- char *img0; /* image origin */
- char *img; /* current image row */
+ schar *img0; /* image origin */
+ schar *img; /* current image row */
int img_step; /* image step */
CvSize img_size; /* ROI size */
CvPoint offset; /* ROI offset: coordinates, added to each contour point */
#define _CV_FIND_CONTOURS_FLAGS_EXTERNAL_ONLY 1
#define _CV_FIND_CONTOURS_FLAGS_HIERARCHIC 2
-/*
+/*
Initializes scanner structure.
Prepare image for scanning ( clear borders and convert all pixels to 0-1.
*/
CV_IMPL CvContourScanner
cvStartFindContours( void* _img, CvMemStorage* storage,
- int header_size, int mode,
+ int header_size, int mode,
int method, CvPoint offset )
{
int y;
memset( scanner, 0, sizeof( *scanner ));
scanner->storage1 = scanner->storage2 = storage;
- scanner->img0 = (char *) img;
- scanner->img = (char *) (img + step);
+ scanner->img0 = (schar *) img;
+ scanner->img = (schar *) (img + step);
scanner->img_step = step;
scanner->img_size.width = size.width - 1; /* exclude rightest column */
scanner->img_size.height = size.height - 1; /* exclude bottomost row */
return scanner;
}
-/*
+/*
Final stage of contour processing.
Three variants possible:
1. Contour, which was retrieved using border following, is added to
It's marked as "link to contour" and h_next pointer of it is set to
new, substituting contour.
- 3. The similar to 2, but when NULL pointer was assigned by
+ 3. The similar to 2, but when NULL pointer was assigned by
icvSubstituteContour function. In this case, the function removes
- retrieved contour completely if plane case and
+ retrieved contour completely if plane case and
leaves header if hierarchical (but doesn't mark header as "link").
------------------------------------------------------------------------
The 1st variant can be used to retrieve and store all the contours from the image
- (with optional convertion from chains to contours using some approximation from
+ (with optional convertion from chains to contours using some approximation from
restriced set of methods). Some characteristics of contour can be computed in the
same pass.
-
+
The usage scheme can look like:
icvContourScanner scanner;
icvCreateMemStorage( &contour_storage, block_size/0 );
...
-
+
cvStartFindContours
( img, contour_storage,
header_size, approx_method,
Second variant is more complex and can be used when someone wants store not
the retrieved contours but transformed ones. (e.g. approximated with some
non-default algorithm ).
-
+
The scheme can be the as following:
icvContourScanner scanner;
icvCreateMemStorage( &temp_storage, block_size/0 );
...
-
+
icvStartFindContours8uC1R
( <img_params>, temp_storage,
header_size, approx_method,
...
}
- new_storage variable is not needed here.
+ new_storage variable is not needed here.
Two notes.
1. Second and third method can interleave. I.e. it is possible to
remain contours that satisfy with some criteria and reject others.
In hierarchic case the resulting tree is the part of original tree with
- some nodes absent. But in the resulting tree the contour1 is a child
+ some nodes absent. But in the resulting tree the contour1 is a child
(may be indirect) of contour2 iff in the original tree the contour1
is a child (may be indirect) of contour2.
*/
}
-/*
+/*
marks domain border with +/-<constant> and stores the contour into CvSeq.
method:
<0 - chain
>0 - simple approximation
*/
static CvStatus
-icvFetchContour( char *ptr,
+icvFetchContour( schar *ptr,
int step,
- CvPoint pt,
- CvSeq* contour,
+ CvPoint pt,
+ CvSeq* contour,
int _method )
{
- const char nbd = 2;
+ const schar nbd = 2;
int deltas[16];
CvSeqWriter writer;
- char *i0 = ptr, *i1, *i3, *i4 = 0;
+ schar *i0 = ptr, *i1, *i3, *i4 = 0;
int prev_s = -1, s, s_end;
int method = _method - 1;
if( s == s_end ) /* single pixel domain */
{
- *i0 = (char) (nbd | -128);
+ *i0 = (schar) (nbd | -128);
if( method >= 0 )
{
CV_WRITE_SEQ_ELEM( pt, writer );
/* check "right" bound */
if( (unsigned) (s - 1) < (unsigned) s_end )
{
- *i3 = (char) (nbd | -128);
+ *i3 = (schar) (nbd | -128);
}
else if( *i3 == 1 )
{
if( method < 0 )
{
- char _s = (char) s;
+ schar _s = (schar) s;
CV_WRITE_SEQ_ELEM( _s, writer );
}
-/*
+/*
trace contour until certain point is met.
returns 1 if met, 0 else.
*/
static int
-icvTraceContour( char *ptr, int step, char *stop_ptr, int is_hole )
+icvTraceContour( schar *ptr, int step, schar *stop_ptr, int is_hole )
{
int deltas[16];
- char *i0 = ptr, *i1, *i3, *i4;
+ schar *i0 = ptr, *i1, *i3, *i4;
int s, s_end;
/* initialize local state */
static CvStatus
-icvFetchContourEx( char* ptr,
+icvFetchContourEx( schar* ptr,
int step,
- CvPoint pt,
+ CvPoint pt,
CvSeq* contour,
- int _method,
+ int _method,
int nbd,
CvRect* _rect )
{
int deltas[16];
CvSeqWriter writer;
- char *i0 = ptr, *i1, *i3, *i4;
+ schar *i0 = ptr, *i1, *i3, *i4;
CvRect rect;
int prev_s = -1, s, s_end;
int method = _method - 1;
if( s == s_end ) /* single pixel domain */
{
- *i0 = (char) (nbd | 0x80);
+ *i0 = (schar) (nbd | 0x80);
if( method >= 0 )
{
CV_WRITE_SEQ_ELEM( pt, writer );
/* check "right" bound */
if( (unsigned) (s - 1) < (unsigned) s_end )
{
- *i3 = (char) (nbd | 0x80);
+ *i3 = (schar) (nbd | 0x80);
}
else if( *i3 == 1 )
{
- *i3 = (char) nbd;
+ *i3 = (schar) nbd;
}
if( method < 0 )
{
- char _s = (char) s;
+ schar _s = (schar) s;
CV_WRITE_SEQ_ELEM( _s, writer );
}
else if( s != prev_s || method == 0 )
CvSeq *
cvFindNextContour( CvContourScanner scanner )
{
- char *img0;
- char *img;
+ schar *img0;
+ schar *img;
int step;
int width, height;
int x, y;
scanner->pt.x = x + 1;
scanner->pt.y = y;
scanner->lnbd = lnbd;
- scanner->img = (char *) img;
+ scanner->img = (schar *) img;
scanner->nbd = nbd;
contour = l_cinfo->contour;
}
-/*
- The function add to tree the last retrieved/substituted contour,
+/*
+ The function add to tree the last retrieved/substituted contour,
releases temp_storage, restores state of dst_storage (if needed), and
returns pointer to root of the contour tree */
CV_IMPL CvSeq *
tmp_prev = &(tmp);
tmp_prev->next = 0;
tmp_prev->link = 0;
-
+
// First line. None of runs is binded
tmp.pt.y = 0;
i = 0;
CV_WRITE_SEQ_ELEM( tmp, writer );
upper_line = (CvLinkedRunPoint*)CV_GET_WRITTEN_ELEM( writer );
-
+
tmp_prev = upper_line;
for( j = 0; j < img_size.width; )
{
upper_total = runs->total - 1;
last_elem = tmp_prev;
tmp_prev->next = 0;
-
+
for( i = 1; i < img_size.height; i++ )
{
//------// Find runs in next line
upper_run = upper_run->next->next;
}
}
- break;
+ break;
}
}// k, n
// Notes:
//F*/
CV_IMPL int
-cvFindContours( void* img, CvMemStorage* storage,
- CvSeq** firstContour, int cntHeaderSize,
- int mode,
+cvFindContours( void* img, CvMemStorage* storage,
+ CvSeq** firstContour, int cntHeaderSize,
+ int mode,
int method, CvPoint offset )
{
CvContourScanner scanner = 0;
CvSeq *contour = 0;
int count = -1;
-
+
CV_FUNCNAME( "cvFindContours" );
__BEGIN__;
}
while( contour != 0 );
- *firstContour = cvEndFindContours( &scanner );
+ *firstContour = cvEndFindContours( &scanner );
}
__END__;