Home | History | Annotate | Download | only in src
      1 /*M///////////////////////////////////////////////////////////////////////////////////////
      2 //
      3 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
      4 //
      5 //  By downloading, copying, installing or using the software you agree to this license.
      6 //  If you do not agree to this license, do not download, install,
      7 //  copy or use the software.
      8 //
      9 //
     10 //                        Intel License Agreement
     11 //                For Open Source Computer Vision Library
     12 //
     13 // Copyright (C) 2000, Intel Corporation, all rights reserved.
     14 // Third party copyrights are property of their respective owners.
     15 //
     16 // Redistribution and use in source and binary forms, with or without modification,
     17 // are permitted provided that the following conditions are met:
     18 //
     19 //   * Redistribution's of source code must retain the above copyright notice,
     20 //     this list of conditions and the following disclaimer.
     21 //
     22 //   * Redistribution's in binary form must reproduce the above copyright notice,
     23 //     this list of conditions and the following disclaimer in the documentation
     24 //     and/or other materials provided with the distribution.
     25 //
     26 //   * The name of Intel Corporation may not be used to endorse or promote products
     27 //     derived from this software without specific prior written permission.
     28 //
     29 // This software is provided by the copyright holders and contributors "as is" and
     30 // any express or implied warranties, including, but not limited to, the implied
     31 // warranties of merchantability and fitness for a particular purpose are disclaimed.
     32 // In no event shall the Intel Corporation or contributors be liable for any direct,
     33 // indirect, incidental, special, exemplary, or consequential damages
     34 // (including, but not limited to, procurement of substitute goods or services;
     35 // loss of use, data, or profits; or business interruption) however caused
     36 // and on any theory of liability, whether in contract, strict liability,
     37 // or tort (including negligence or otherwise) arising in any way out of
     38 // the use of this software, even if advised of the possibility of such damage.
     39 //
     40 //M*/
     41 
     42 #include "precomp.hpp"
     43 
     44 CV_IMPL CvSeq* cvPointSeqFromMat( int seq_kind, const CvArr* arr,
     45                                   CvContour* contour_header, CvSeqBlock* block )
     46 {
     47     CV_Assert( arr != 0 && contour_header != 0 && block != 0 );
     48 
     49     int eltype;
     50     CvMat hdr;
     51     CvMat* mat = (CvMat*)arr;
     52 
     53     if( !CV_IS_MAT( mat ))
     54         CV_Error( CV_StsBadArg, "Input array is not a valid matrix" );
     55 
     56     if( CV_MAT_CN(mat->type) == 1 && mat->width == 2 )
     57         mat = cvReshape(mat, &hdr, 2);
     58 
     59     eltype = CV_MAT_TYPE( mat->type );
     60     if( eltype != CV_32SC2 && eltype != CV_32FC2 )
     61         CV_Error( CV_StsUnsupportedFormat,
     62         "The matrix can not be converted to point sequence because of "
     63         "inappropriate element type" );
     64 
     65     if( (mat->width != 1 && mat->height != 1) || !CV_IS_MAT_CONT(mat->type))
     66         CV_Error( CV_StsBadArg,
     67         "The matrix converted to point sequence must be "
     68         "1-dimensional and continuous" );
     69 
     70     cvMakeSeqHeaderForArray(
     71             (seq_kind & (CV_SEQ_KIND_MASK|CV_SEQ_FLAG_CLOSED)) | eltype,
     72             sizeof(CvContour), CV_ELEM_SIZE(eltype), mat->data.ptr,
     73             mat->width*mat->height, (CvSeq*)contour_header, block );
     74 
     75     return (CvSeq*)contour_header;
     76 }
     77 
     78 CV_IMPL void
     79 cvCopyMakeBorder( const CvArr* srcarr, CvArr* dstarr, CvPoint offset,
     80                   int borderType, CvScalar value )
     81 {
     82     cv::Mat src = cv::cvarrToMat(srcarr), dst = cv::cvarrToMat(dstarr);
     83     int left = offset.x, right = dst.cols - src.cols - left;
     84     int top = offset.y, bottom = dst.rows - src.rows - top;
     85 
     86     CV_Assert( dst.type() == src.type() );
     87     cv::copyMakeBorder( src, dst, top, bottom, left, right, borderType, value );
     88 }
     89 
     90 /* End of file. */
     91