| 2583 | |
| 2584 | |
| 2585 | void cv::findNonZero( InputArray _src, OutputArray _idx ) |
| 2586 | { |
| 2587 | Mat src = _src.getMat(); |
| 2588 | CV_Assert( src.type() == CV_8UC1 ); |
| 2589 | int n = countNonZero(src); |
| 2590 | if (n == 0) |
| 2591 | { |
| 2592 | _idx.release(); |
| 2593 | return; |
| 2594 | } |
| 2595 | if( _idx.kind() == _InputArray::MAT && !_idx.getMatRef().isContinuous() ) |
| 2596 | _idx.release(); |
| 2597 | _idx.create(n, 1, CV_32SC2); |
| 2598 | Mat idx = _idx.getMat(); |
| 2599 | CV_Assert(idx.isContinuous()); |
| 2600 | Point* idx_ptr = (Point*)idx.data; |
| 2601 | |
| 2602 | for( int i = 0; i < src.rows; i++ ) |
| 2603 | { |
| 2604 | const uchar* bin_ptr = src.ptr(i); |
| 2605 | for( int j = 0; j < src.cols; j++ ) |
| 2606 | if( bin_ptr[j] ) |
| 2607 | *idx_ptr++ = Point(j, i); |
| 2608 | } |
| 2609 | } |
| 2610 | |
| 2611 | |
| 2612 | CV_IMPL CvScalar cvSum( const CvArr* srcarr ) |