Renesas GR-PEACH OpenCV Development / gr-peach-opencv-project-sd-card_update

Fork of gr-peach-opencv-project-sd-card by the do

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers utils.cpp Source File

utils.cpp

00001 /*M///////////////////////////////////////////////////////////////////////////////////////
00002 //
00003 //  IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
00004 //
00005 //  By downloading, copying, installing or using the software you agree to this license.
00006 //  If you do not agree to this license, do not download, install,
00007 //  copy or use the software.
00008 //
00009 //
00010 //                        Intel License Agreement
00011 //                For Open Source Computer Vision Library
00012 //
00013 // Copyright (C) 2000, Intel Corporation, all rights reserved.
00014 // Third party copyrights are property of their respective owners.
00015 //
00016 // Redistribution and use in source and binary forms, with or without modification,
00017 // are permitted provided that the following conditions are met:
00018 //
00019 //   * Redistribution's of source code must retain the above copyright notice,
00020 //     this list of conditions and the following disclaimer.
00021 //
00022 //   * Redistribution's in binary form must reproduce the above copyright notice,
00023 //     this list of conditions and the following disclaimer in the documentation
00024 //     and/or other materials provided with the distribution.
00025 //
00026 //   * The name of Intel Corporation may not be used to endorse or promote products
00027 //     derived from this software without specific prior written permission.
00028 //
00029 // This software is provided by the copyright holders and contributors "as is" and
00030 // any express or implied warranties, including, but not limited to, the implied
00031 // warranties of merchantability and fitness for a particular purpose are disclaimed.
00032 // In no event shall the Intel Corporation or contributors be liable for any direct,
00033 // indirect, incidental, special, exemplary, or consequential damages
00034 // (including, but not limited to, procurement of substitute goods or services;
00035 // loss of use, data, or profits; or business interruption) however caused
00036 // and on any theory of liability, whether in contract, strict liability,
00037 // or tort (including negligence or otherwise) arising in any way out of
00038 // the use of this software, even if advised of the possibility of such damage.
00039 //
00040 //M*/
00041 
00042 #include "precomp.hpp"
00043 
00044 CV_IMPL CvSeq* cvPointSeqFromMat( int seq_kind, const CvArr* arr,
00045                                   CvContour* contour_header, CvSeqBlock* block )
00046 {
00047     CV_Assert( arr != 0 && contour_header != 0 && block != 0 );
00048 
00049     int eltype;
00050     CvMat hdr;
00051     CvMat* mat = (CvMat*)arr;
00052 
00053     if( !CV_IS_MAT( mat ))
00054         CV_Error( CV_StsBadArg, "Input array is not a valid matrix" );
00055 
00056     if( CV_MAT_CN(mat->type) == 1 && mat->width == 2 )
00057         mat = cvReshape(mat, &hdr, 2);
00058 
00059     eltype = CV_MAT_TYPE( mat->type );
00060     if( eltype != CV_32SC2 && eltype != CV_32FC2 )
00061         CV_Error( CV_StsUnsupportedFormat,
00062         "The matrix can not be converted to point sequence because of "
00063         "inappropriate element type" );
00064 
00065     if( (mat->width != 1 && mat->height != 1) || !CV_IS_MAT_CONT(mat->type))
00066         CV_Error( CV_StsBadArg,
00067         "The matrix converted to point sequence must be "
00068         "1-dimensional and continuous" );
00069 
00070     cvMakeSeqHeaderForArray(
00071             (seq_kind & (CV_SEQ_KIND_MASK|CV_SEQ_FLAG_CLOSED)) | eltype,
00072             sizeof(CvContour), CV_ELEM_SIZE(eltype), mat->data.ptr,
00073             mat->width*mat->height, (CvSeq*)contour_header, block );
00074 
00075     return (CvSeq*)contour_header;
00076 }
00077 
00078 CV_IMPL void
00079 cvCopyMakeBorder( const CvArr* srcarr, CvArr* dstarr, CvPoint offset,
00080                   int borderType, CvScalar  value )
00081 {
00082     cv::Mat src = cv::cvarrToMat(srcarr), dst = cv::cvarrToMat(dstarr);
00083     int left = offset.x, right = dst.cols - src.cols - left;
00084     int top = offset.y, bottom = dst.rows - src.rows - top;
00085 
00086     CV_Assert( dst.type() == src.type() );
00087     cv::copyMakeBorder( src, dst, top, bottom, left, right, borderType, value );
00088 }
00089 
00090 /* End of file. */
00091