| 349 | |
| 350 | |
| 351 | CV_IMPL CvBox2D |
| 352 | cvMinAreaRect2( const CvArr* array, CvMemStorage* storage ) |
| 353 | { |
| 354 | cv::Ptr<CvMemStorage> temp_storage; |
| 355 | CvBox2D box; |
| 356 | cv::AutoBuffer<CvPoint2D32f> _points; |
| 357 | CvPoint2D32f* points; |
| 358 | |
| 359 | memset(&box, 0, sizeof(box)); |
| 360 | |
| 361 | int i, n; |
| 362 | CvSeqReader reader; |
| 363 | CvContour contour_header; |
| 364 | CvSeqBlock block; |
| 365 | CvSeq* ptseq = (CvSeq*)array; |
| 366 | CvPoint2D32f out[3]; |
| 367 | |
| 368 | if( CV_IS_SEQ(ptseq) ) |
| 369 | { |
| 370 | if( !CV_IS_SEQ_POINT_SET(ptseq) && |
| 371 | (CV_SEQ_KIND(ptseq) != CV_SEQ_KIND_CURVE || |
| 372 | CV_SEQ_ELTYPE(ptseq) != CV_SEQ_ELTYPE_PPOINT )) |
| 373 | CV_Error( CV_StsUnsupportedFormat, |
| 374 | "Input sequence must consist of 2d points or pointers to 2d points" ); |
| 375 | if( !storage ) |
| 376 | storage = ptseq->storage; |
| 377 | } |
| 378 | else |
| 379 | { |
| 380 | ptseq = cvPointSeqFromMat( CV_SEQ_KIND_GENERIC, array, &contour_header, &block ); |
| 381 | } |
| 382 | |
| 383 | if( storage ) |
| 384 | { |
| 385 | temp_storage = cvCreateChildMemStorage( storage ); |
| 386 | } |
| 387 | else |
| 388 | { |
| 389 | temp_storage = cvCreateMemStorage(1 << 10); |
| 390 | } |
| 391 | |
| 392 | ptseq = cvConvexHull2( ptseq, temp_storage, CV_CLOCKWISE, 1 ); |
| 393 | n = ptseq->total; |
| 394 | |
| 395 | _points.allocate(n); |
| 396 | points = _points; |
| 397 | cvStartReadSeq( ptseq, &reader ); |
| 398 | |
| 399 | if( CV_SEQ_ELTYPE( ptseq ) == CV_32SC2 ) |
| 400 | { |
| 401 | for( i = 0; i < n; i++ ) |
| 402 | { |
| 403 | CvPoint pt; |
| 404 | CV_READ_SEQ_ELEM( pt, reader ); |
| 405 | points[i].x = (float)pt.x; |
| 406 | points[i].y = (float)pt.y; |
| 407 | } |
| 408 | } |
no test coverage detected