openCV library for Renesas RZ/A

Dependents:   RZ_A2M_Mbed_samples

Committer:
RyoheiHagimoto
Date:
Fri Jan 29 04:53:38 2021 +0000
Revision:
0:0e0631af0305
copied from https://github.com/d-kato/opencv-lib.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
RyoheiHagimoto 0:0e0631af0305 1 /*M//////////////////////////////////////////////////////////////////////////////
RyoheiHagimoto 0:0e0631af0305 2 // IMPORTANT: READ BEFORE DOWNLOADING, COPYING, INSTALLING OR USING.
RyoheiHagimoto 0:0e0631af0305 3 //
RyoheiHagimoto 0:0e0631af0305 4 // By downloading, copying, installing or using the software you agree to
RyoheiHagimoto 0:0e0631af0305 5 // this license. If you do not agree to this license, do not download,
RyoheiHagimoto 0:0e0631af0305 6 // install, copy or use the software.
RyoheiHagimoto 0:0e0631af0305 7 //
RyoheiHagimoto 0:0e0631af0305 8 // License Agreement
RyoheiHagimoto 0:0e0631af0305 9 // For Open Source Computer Vision Library
RyoheiHagimoto 0:0e0631af0305 10 //
RyoheiHagimoto 0:0e0631af0305 11 // Copyright (C) 2008, Google, all rights reserved.
RyoheiHagimoto 0:0e0631af0305 12 // Third party copyrights are property of their respective owners.
RyoheiHagimoto 0:0e0631af0305 13 //
RyoheiHagimoto 0:0e0631af0305 14 // Redistribution and use in source and binary forms, with or without
RyoheiHagimoto 0:0e0631af0305 15 // modification, are permitted provided that the following conditions are met:
RyoheiHagimoto 0:0e0631af0305 16 //
RyoheiHagimoto 0:0e0631af0305 17 // * Redistribution's of source code must retain the above copyright notice,
RyoheiHagimoto 0:0e0631af0305 18 // this list of conditions and the following disclaimer.
RyoheiHagimoto 0:0e0631af0305 19 //
RyoheiHagimoto 0:0e0631af0305 20 // * Redistribution's in binary form must reproduce the above copyright notice,
RyoheiHagimoto 0:0e0631af0305 21 // this list of conditions and the following disclaimer in the documentation
RyoheiHagimoto 0:0e0631af0305 22 // and/or other materials provided with the distribution.
RyoheiHagimoto 0:0e0631af0305 23 //
RyoheiHagimoto 0:0e0631af0305 24 // * The name of Intel Corporation or contributors may not be used to endorse
RyoheiHagimoto 0:0e0631af0305 25 // or promote products derived from this software without specific
RyoheiHagimoto 0:0e0631af0305 26 // prior written permission.
RyoheiHagimoto 0:0e0631af0305 27 //
RyoheiHagimoto 0:0e0631af0305 28 // This software is provided by the copyright holders and contributors "as is"
RyoheiHagimoto 0:0e0631af0305 29 // and any express or implied warranties, including, but not limited to, the
RyoheiHagimoto 0:0e0631af0305 30 // implied warranties of merchantability and fitness for a particular purpose
RyoheiHagimoto 0:0e0631af0305 31 // are disclaimed. In no event shall the Intel Corporation or contributors be
RyoheiHagimoto 0:0e0631af0305 32 // liable for any direct, indirect, incidental, special, exemplary, or
RyoheiHagimoto 0:0e0631af0305 33 // consequential damages
RyoheiHagimoto 0:0e0631af0305 34 // (including, but not limited to, procurement of substitute goods or services;
RyoheiHagimoto 0:0e0631af0305 35 // loss of use, data, or profits; or business interruption) however caused
RyoheiHagimoto 0:0e0631af0305 36 // and on any theory of liability, whether in contract, strict liability,
RyoheiHagimoto 0:0e0631af0305 37 // or tort (including negligence or otherwise) arising in any way out of
RyoheiHagimoto 0:0e0631af0305 38 // the use of this software, even if advised of the possibility of such damage.
RyoheiHagimoto 0:0e0631af0305 39 /////////////////////////////////////////////////////////////////////////////////
RyoheiHagimoto 0:0e0631af0305 40 //M*/
RyoheiHagimoto 0:0e0631af0305 41
RyoheiHagimoto 0:0e0631af0305 42 #ifndef OPENCV_CORE_WIMAGE_HPP
RyoheiHagimoto 0:0e0631af0305 43 #define OPENCV_CORE_WIMAGE_HPP
RyoheiHagimoto 0:0e0631af0305 44
RyoheiHagimoto 0:0e0631af0305 45 #include "opencv2/core/core_c.h"
RyoheiHagimoto 0:0e0631af0305 46
RyoheiHagimoto 0:0e0631af0305 47 #ifdef __cplusplus
RyoheiHagimoto 0:0e0631af0305 48
RyoheiHagimoto 0:0e0631af0305 49 namespace cv {
RyoheiHagimoto 0:0e0631af0305 50
RyoheiHagimoto 0:0e0631af0305 51 //! @addtogroup core
RyoheiHagimoto 0:0e0631af0305 52 //! @{
RyoheiHagimoto 0:0e0631af0305 53
RyoheiHagimoto 0:0e0631af0305 54 template <typename T> class WImage;
RyoheiHagimoto 0:0e0631af0305 55 template <typename T> class WImageBuffer;
RyoheiHagimoto 0:0e0631af0305 56 template <typename T> class WImageView;
RyoheiHagimoto 0:0e0631af0305 57
RyoheiHagimoto 0:0e0631af0305 58 template<typename T, int C> class WImageC;
RyoheiHagimoto 0:0e0631af0305 59 template<typename T, int C> class WImageBufferC;
RyoheiHagimoto 0:0e0631af0305 60 template<typename T, int C> class WImageViewC;
RyoheiHagimoto 0:0e0631af0305 61
RyoheiHagimoto 0:0e0631af0305 62 // Commonly used typedefs.
RyoheiHagimoto 0:0e0631af0305 63 typedef WImage<uchar> WImage_b;
RyoheiHagimoto 0:0e0631af0305 64 typedef WImageView<uchar> WImageView_b;
RyoheiHagimoto 0:0e0631af0305 65 typedef WImageBuffer<uchar> WImageBuffer_b;
RyoheiHagimoto 0:0e0631af0305 66
RyoheiHagimoto 0:0e0631af0305 67 typedef WImageC<uchar, 1> WImage1_b;
RyoheiHagimoto 0:0e0631af0305 68 typedef WImageViewC<uchar, 1> WImageView1_b;
RyoheiHagimoto 0:0e0631af0305 69 typedef WImageBufferC<uchar, 1> WImageBuffer1_b;
RyoheiHagimoto 0:0e0631af0305 70
RyoheiHagimoto 0:0e0631af0305 71 typedef WImageC<uchar, 3> WImage3_b;
RyoheiHagimoto 0:0e0631af0305 72 typedef WImageViewC<uchar, 3> WImageView3_b;
RyoheiHagimoto 0:0e0631af0305 73 typedef WImageBufferC<uchar, 3> WImageBuffer3_b;
RyoheiHagimoto 0:0e0631af0305 74
RyoheiHagimoto 0:0e0631af0305 75 typedef WImage<float> WImage_f;
RyoheiHagimoto 0:0e0631af0305 76 typedef WImageView<float> WImageView_f;
RyoheiHagimoto 0:0e0631af0305 77 typedef WImageBuffer<float> WImageBuffer_f;
RyoheiHagimoto 0:0e0631af0305 78
RyoheiHagimoto 0:0e0631af0305 79 typedef WImageC<float, 1> WImage1_f;
RyoheiHagimoto 0:0e0631af0305 80 typedef WImageViewC<float, 1> WImageView1_f;
RyoheiHagimoto 0:0e0631af0305 81 typedef WImageBufferC<float, 1> WImageBuffer1_f;
RyoheiHagimoto 0:0e0631af0305 82
RyoheiHagimoto 0:0e0631af0305 83 typedef WImageC<float, 3> WImage3_f;
RyoheiHagimoto 0:0e0631af0305 84 typedef WImageViewC<float, 3> WImageView3_f;
RyoheiHagimoto 0:0e0631af0305 85 typedef WImageBufferC<float, 3> WImageBuffer3_f;
RyoheiHagimoto 0:0e0631af0305 86
RyoheiHagimoto 0:0e0631af0305 87 // There isn't a standard for signed and unsigned short so be more
RyoheiHagimoto 0:0e0631af0305 88 // explicit in the typename for these cases.
RyoheiHagimoto 0:0e0631af0305 89 typedef WImage<short> WImage_16s;
RyoheiHagimoto 0:0e0631af0305 90 typedef WImageView<short> WImageView_16s;
RyoheiHagimoto 0:0e0631af0305 91 typedef WImageBuffer<short> WImageBuffer_16s;
RyoheiHagimoto 0:0e0631af0305 92
RyoheiHagimoto 0:0e0631af0305 93 typedef WImageC<short, 1> WImage1_16s;
RyoheiHagimoto 0:0e0631af0305 94 typedef WImageViewC<short, 1> WImageView1_16s;
RyoheiHagimoto 0:0e0631af0305 95 typedef WImageBufferC<short, 1> WImageBuffer1_16s;
RyoheiHagimoto 0:0e0631af0305 96
RyoheiHagimoto 0:0e0631af0305 97 typedef WImageC<short, 3> WImage3_16s;
RyoheiHagimoto 0:0e0631af0305 98 typedef WImageViewC<short, 3> WImageView3_16s;
RyoheiHagimoto 0:0e0631af0305 99 typedef WImageBufferC<short, 3> WImageBuffer3_16s;
RyoheiHagimoto 0:0e0631af0305 100
RyoheiHagimoto 0:0e0631af0305 101 typedef WImage<ushort> WImage_16u;
RyoheiHagimoto 0:0e0631af0305 102 typedef WImageView<ushort> WImageView_16u;
RyoheiHagimoto 0:0e0631af0305 103 typedef WImageBuffer<ushort> WImageBuffer_16u;
RyoheiHagimoto 0:0e0631af0305 104
RyoheiHagimoto 0:0e0631af0305 105 typedef WImageC<ushort, 1> WImage1_16u;
RyoheiHagimoto 0:0e0631af0305 106 typedef WImageViewC<ushort, 1> WImageView1_16u;
RyoheiHagimoto 0:0e0631af0305 107 typedef WImageBufferC<ushort, 1> WImageBuffer1_16u;
RyoheiHagimoto 0:0e0631af0305 108
RyoheiHagimoto 0:0e0631af0305 109 typedef WImageC<ushort, 3> WImage3_16u;
RyoheiHagimoto 0:0e0631af0305 110 typedef WImageViewC<ushort, 3> WImageView3_16u;
RyoheiHagimoto 0:0e0631af0305 111 typedef WImageBufferC<ushort, 3> WImageBuffer3_16u;
RyoheiHagimoto 0:0e0631af0305 112
RyoheiHagimoto 0:0e0631af0305 113 /** @brief Image class which provides a thin layer around an IplImage.
RyoheiHagimoto 0:0e0631af0305 114
RyoheiHagimoto 0:0e0631af0305 115 The goals of the class design are:
RyoheiHagimoto 0:0e0631af0305 116
RyoheiHagimoto 0:0e0631af0305 117 -# All the data has explicit ownership to avoid memory leaks
RyoheiHagimoto 0:0e0631af0305 118 -# No hidden allocations or copies for performance.
RyoheiHagimoto 0:0e0631af0305 119 -# Easy access to OpenCV methods (which will access IPP if available)
RyoheiHagimoto 0:0e0631af0305 120 -# Can easily treat external data as an image
RyoheiHagimoto 0:0e0631af0305 121 -# Easy to create images which are subsets of other images
RyoheiHagimoto 0:0e0631af0305 122 -# Fast pixel access which can take advantage of number of channels if known at compile time.
RyoheiHagimoto 0:0e0631af0305 123
RyoheiHagimoto 0:0e0631af0305 124 The WImage class is the image class which provides the data accessors. The 'W' comes from the fact
RyoheiHagimoto 0:0e0631af0305 125 that it is also a wrapper around the popular but inconvenient IplImage class. A WImage can be
RyoheiHagimoto 0:0e0631af0305 126 constructed either using a WImageBuffer class which allocates and frees the data, or using a
RyoheiHagimoto 0:0e0631af0305 127 WImageView class which constructs a subimage or a view into external data. The view class does no
RyoheiHagimoto 0:0e0631af0305 128 memory management. Each class actually has two versions, one when the number of channels is known
RyoheiHagimoto 0:0e0631af0305 129 at compile time and one when it isn't. Using the one with the number of channels specified can
RyoheiHagimoto 0:0e0631af0305 130 provide some compile time optimizations by using the fact that the number of channels is a
RyoheiHagimoto 0:0e0631af0305 131 constant.
RyoheiHagimoto 0:0e0631af0305 132
RyoheiHagimoto 0:0e0631af0305 133 We use the convention (c,r) to refer to column c and row r with (0,0) being the upper left corner.
RyoheiHagimoto 0:0e0631af0305 134 This is similar to standard Euclidean coordinates with the first coordinate varying in the
RyoheiHagimoto 0:0e0631af0305 135 horizontal direction and the second coordinate varying in the vertical direction. Thus (c,r) is
RyoheiHagimoto 0:0e0631af0305 136 usually in the domain [0, width) X [0, height)
RyoheiHagimoto 0:0e0631af0305 137
RyoheiHagimoto 0:0e0631af0305 138 Example usage:
RyoheiHagimoto 0:0e0631af0305 139 @code
RyoheiHagimoto 0:0e0631af0305 140 WImageBuffer3_b im(5,7); // Make a 5X7 3 channel image of type uchar
RyoheiHagimoto 0:0e0631af0305 141 WImageView3_b sub_im(im, 2,2, 3,3); // 3X3 submatrix
RyoheiHagimoto 0:0e0631af0305 142 vector<float> vec(10, 3.0f);
RyoheiHagimoto 0:0e0631af0305 143 WImageView1_f user_im(&vec[0], 2, 5); // 2X5 image w/ supplied data
RyoheiHagimoto 0:0e0631af0305 144
RyoheiHagimoto 0:0e0631af0305 145 im.SetZero(); // same as cvSetZero(im.Ipl())
RyoheiHagimoto 0:0e0631af0305 146 *im(2, 3) = 15; // Modify the element at column 2, row 3
RyoheiHagimoto 0:0e0631af0305 147 MySetRand(&sub_im);
RyoheiHagimoto 0:0e0631af0305 148
RyoheiHagimoto 0:0e0631af0305 149 // Copy the second row into the first. This can be done with no memory
RyoheiHagimoto 0:0e0631af0305 150 // allocation and will use SSE if IPP is available.
RyoheiHagimoto 0:0e0631af0305 151 int w = im.Width();
RyoheiHagimoto 0:0e0631af0305 152 im.View(0,0, w,1).CopyFrom(im.View(0,1, w,1));
RyoheiHagimoto 0:0e0631af0305 153
RyoheiHagimoto 0:0e0631af0305 154 // Doesn't care about source of data since using WImage
RyoheiHagimoto 0:0e0631af0305 155 void MySetRand(WImage_b* im) { // Works with any number of channels
RyoheiHagimoto 0:0e0631af0305 156 for (int r = 0; r < im->Height(); ++r) {
RyoheiHagimoto 0:0e0631af0305 157 float* row = im->Row(r);
RyoheiHagimoto 0:0e0631af0305 158 for (int c = 0; c < im->Width(); ++c) {
RyoheiHagimoto 0:0e0631af0305 159 for (int ch = 0; ch < im->Channels(); ++ch, ++row) {
RyoheiHagimoto 0:0e0631af0305 160 *row = uchar(rand() & 255);
RyoheiHagimoto 0:0e0631af0305 161 }
RyoheiHagimoto 0:0e0631af0305 162 }
RyoheiHagimoto 0:0e0631af0305 163 }
RyoheiHagimoto 0:0e0631af0305 164 }
RyoheiHagimoto 0:0e0631af0305 165 @endcode
RyoheiHagimoto 0:0e0631af0305 166
RyoheiHagimoto 0:0e0631af0305 167 Functions that are not part of the basic image allocation, viewing, and access should come from
RyoheiHagimoto 0:0e0631af0305 168 OpenCV, except some useful functions that are not part of OpenCV can be found in wimage_util.h
RyoheiHagimoto 0:0e0631af0305 169 */
RyoheiHagimoto 0:0e0631af0305 170 template<typename T>
RyoheiHagimoto 0:0e0631af0305 171 class WImage
RyoheiHagimoto 0:0e0631af0305 172 {
RyoheiHagimoto 0:0e0631af0305 173 public:
RyoheiHagimoto 0:0e0631af0305 174 typedef T BaseType;
RyoheiHagimoto 0:0e0631af0305 175
RyoheiHagimoto 0:0e0631af0305 176 // WImage is an abstract class with no other virtual methods so make the
RyoheiHagimoto 0:0e0631af0305 177 // destructor virtual.
RyoheiHagimoto 0:0e0631af0305 178 virtual ~WImage() = 0;
RyoheiHagimoto 0:0e0631af0305 179
RyoheiHagimoto 0:0e0631af0305 180 // Accessors
RyoheiHagimoto 0:0e0631af0305 181 IplImage* Ipl() {return image_; }
RyoheiHagimoto 0:0e0631af0305 182 const IplImage* Ipl() const {return image_; }
RyoheiHagimoto 0:0e0631af0305 183 T* ImageData() { return reinterpret_cast<T*>(image_->imageData); }
RyoheiHagimoto 0:0e0631af0305 184 const T* ImageData() const {
RyoheiHagimoto 0:0e0631af0305 185 return reinterpret_cast<const T*>(image_->imageData);
RyoheiHagimoto 0:0e0631af0305 186 }
RyoheiHagimoto 0:0e0631af0305 187
RyoheiHagimoto 0:0e0631af0305 188 int Width() const {return image_->width; }
RyoheiHagimoto 0:0e0631af0305 189 int Height() const {return image_->height; }
RyoheiHagimoto 0:0e0631af0305 190
RyoheiHagimoto 0:0e0631af0305 191 // WidthStep is the number of bytes to go to the pixel with the next y coord
RyoheiHagimoto 0:0e0631af0305 192 int WidthStep() const {return image_->widthStep; }
RyoheiHagimoto 0:0e0631af0305 193
RyoheiHagimoto 0:0e0631af0305 194 int Channels() const {return image_->nChannels; }
RyoheiHagimoto 0:0e0631af0305 195 int ChannelSize() const {return sizeof(T); } // number of bytes per channel
RyoheiHagimoto 0:0e0631af0305 196
RyoheiHagimoto 0:0e0631af0305 197 // Number of bytes per pixel
RyoheiHagimoto 0:0e0631af0305 198 int PixelSize() const {return Channels() * ChannelSize(); }
RyoheiHagimoto 0:0e0631af0305 199
RyoheiHagimoto 0:0e0631af0305 200 // Return depth type (e.g. IPL_DEPTH_8U, IPL_DEPTH_32F) which is the number
RyoheiHagimoto 0:0e0631af0305 201 // of bits per channel and with the signed bit set.
RyoheiHagimoto 0:0e0631af0305 202 // This is known at compile time using specializations.
RyoheiHagimoto 0:0e0631af0305 203 int Depth() const;
RyoheiHagimoto 0:0e0631af0305 204
RyoheiHagimoto 0:0e0631af0305 205 inline const T* Row(int r) const {
RyoheiHagimoto 0:0e0631af0305 206 return reinterpret_cast<T*>(image_->imageData + r*image_->widthStep);
RyoheiHagimoto 0:0e0631af0305 207 }
RyoheiHagimoto 0:0e0631af0305 208
RyoheiHagimoto 0:0e0631af0305 209 inline T* Row(int r) {
RyoheiHagimoto 0:0e0631af0305 210 return reinterpret_cast<T*>(image_->imageData + r*image_->widthStep);
RyoheiHagimoto 0:0e0631af0305 211 }
RyoheiHagimoto 0:0e0631af0305 212
RyoheiHagimoto 0:0e0631af0305 213 // Pixel accessors which returns a pointer to the start of the channel
RyoheiHagimoto 0:0e0631af0305 214 inline T* operator() (int c, int r) {
RyoheiHagimoto 0:0e0631af0305 215 return reinterpret_cast<T*>(image_->imageData + r*image_->widthStep) +
RyoheiHagimoto 0:0e0631af0305 216 c*Channels();
RyoheiHagimoto 0:0e0631af0305 217 }
RyoheiHagimoto 0:0e0631af0305 218
RyoheiHagimoto 0:0e0631af0305 219 inline const T* operator() (int c, int r) const {
RyoheiHagimoto 0:0e0631af0305 220 return reinterpret_cast<T*>(image_->imageData + r*image_->widthStep) +
RyoheiHagimoto 0:0e0631af0305 221 c*Channels();
RyoheiHagimoto 0:0e0631af0305 222 }
RyoheiHagimoto 0:0e0631af0305 223
RyoheiHagimoto 0:0e0631af0305 224 // Copy the contents from another image which is just a convenience to cvCopy
RyoheiHagimoto 0:0e0631af0305 225 void CopyFrom(const WImage<T>& src) { cvCopy(src.Ipl(), image_); }
RyoheiHagimoto 0:0e0631af0305 226
RyoheiHagimoto 0:0e0631af0305 227 // Set contents to zero which is just a convenient to cvSetZero
RyoheiHagimoto 0:0e0631af0305 228 void SetZero() { cvSetZero(image_); }
RyoheiHagimoto 0:0e0631af0305 229
RyoheiHagimoto 0:0e0631af0305 230 // Construct a view into a region of this image
RyoheiHagimoto 0:0e0631af0305 231 WImageView<T> View(int c, int r, int width, int height);
RyoheiHagimoto 0:0e0631af0305 232
RyoheiHagimoto 0:0e0631af0305 233 protected:
RyoheiHagimoto 0:0e0631af0305 234 // Disallow copy and assignment
RyoheiHagimoto 0:0e0631af0305 235 WImage(const WImage&);
RyoheiHagimoto 0:0e0631af0305 236 void operator=(const WImage&);
RyoheiHagimoto 0:0e0631af0305 237
RyoheiHagimoto 0:0e0631af0305 238 explicit WImage(IplImage* img) : image_(img) {
RyoheiHagimoto 0:0e0631af0305 239 assert(!img || img->depth == Depth());
RyoheiHagimoto 0:0e0631af0305 240 }
RyoheiHagimoto 0:0e0631af0305 241
RyoheiHagimoto 0:0e0631af0305 242 void SetIpl(IplImage* image) {
RyoheiHagimoto 0:0e0631af0305 243 assert(!image || image->depth == Depth());
RyoheiHagimoto 0:0e0631af0305 244 image_ = image;
RyoheiHagimoto 0:0e0631af0305 245 }
RyoheiHagimoto 0:0e0631af0305 246
RyoheiHagimoto 0:0e0631af0305 247 IplImage* image_;
RyoheiHagimoto 0:0e0631af0305 248 };
RyoheiHagimoto 0:0e0631af0305 249
RyoheiHagimoto 0:0e0631af0305 250
RyoheiHagimoto 0:0e0631af0305 251 /** Image class when both the pixel type and number of channels
RyoheiHagimoto 0:0e0631af0305 252 are known at compile time. This wrapper will speed up some of the operations
RyoheiHagimoto 0:0e0631af0305 253 like accessing individual pixels using the () operator.
RyoheiHagimoto 0:0e0631af0305 254 */
RyoheiHagimoto 0:0e0631af0305 255 template<typename T, int C>
RyoheiHagimoto 0:0e0631af0305 256 class WImageC : public WImage<T>
RyoheiHagimoto 0:0e0631af0305 257 {
RyoheiHagimoto 0:0e0631af0305 258 public:
RyoheiHagimoto 0:0e0631af0305 259 typedef typename WImage<T>::BaseType BaseType;
RyoheiHagimoto 0:0e0631af0305 260 enum { kChannels = C };
RyoheiHagimoto 0:0e0631af0305 261
RyoheiHagimoto 0:0e0631af0305 262 explicit WImageC(IplImage* img) : WImage<T>(img) {
RyoheiHagimoto 0:0e0631af0305 263 assert(!img || img->nChannels == Channels());
RyoheiHagimoto 0:0e0631af0305 264 }
RyoheiHagimoto 0:0e0631af0305 265
RyoheiHagimoto 0:0e0631af0305 266 // Construct a view into a region of this image
RyoheiHagimoto 0:0e0631af0305 267 WImageViewC<T, C> View(int c, int r, int width, int height);
RyoheiHagimoto 0:0e0631af0305 268
RyoheiHagimoto 0:0e0631af0305 269 // Copy the contents from another image which is just a convenience to cvCopy
RyoheiHagimoto 0:0e0631af0305 270 void CopyFrom(const WImageC<T, C>& src) {
RyoheiHagimoto 0:0e0631af0305 271 cvCopy(src.Ipl(), WImage<T>::image_);
RyoheiHagimoto 0:0e0631af0305 272 }
RyoheiHagimoto 0:0e0631af0305 273
RyoheiHagimoto 0:0e0631af0305 274 // WImageC is an abstract class with no other virtual methods so make the
RyoheiHagimoto 0:0e0631af0305 275 // destructor virtual.
RyoheiHagimoto 0:0e0631af0305 276 virtual ~WImageC() = 0;
RyoheiHagimoto 0:0e0631af0305 277
RyoheiHagimoto 0:0e0631af0305 278 int Channels() const {return C; }
RyoheiHagimoto 0:0e0631af0305 279
RyoheiHagimoto 0:0e0631af0305 280 protected:
RyoheiHagimoto 0:0e0631af0305 281 // Disallow copy and assignment
RyoheiHagimoto 0:0e0631af0305 282 WImageC(const WImageC&);
RyoheiHagimoto 0:0e0631af0305 283 void operator=(const WImageC&);
RyoheiHagimoto 0:0e0631af0305 284
RyoheiHagimoto 0:0e0631af0305 285 void SetIpl(IplImage* image) {
RyoheiHagimoto 0:0e0631af0305 286 assert(!image || image->depth == WImage<T>::Depth());
RyoheiHagimoto 0:0e0631af0305 287 WImage<T>::SetIpl(image);
RyoheiHagimoto 0:0e0631af0305 288 }
RyoheiHagimoto 0:0e0631af0305 289 };
RyoheiHagimoto 0:0e0631af0305 290
RyoheiHagimoto 0:0e0631af0305 291 /** Image class which owns the data, so it can be allocated and is always
RyoheiHagimoto 0:0e0631af0305 292 freed. It cannot be copied but can be explicity cloned.
RyoheiHagimoto 0:0e0631af0305 293 */
RyoheiHagimoto 0:0e0631af0305 294 template<typename T>
RyoheiHagimoto 0:0e0631af0305 295 class WImageBuffer : public WImage<T>
RyoheiHagimoto 0:0e0631af0305 296 {
RyoheiHagimoto 0:0e0631af0305 297 public:
RyoheiHagimoto 0:0e0631af0305 298 typedef typename WImage<T>::BaseType BaseType;
RyoheiHagimoto 0:0e0631af0305 299
RyoheiHagimoto 0:0e0631af0305 300 // Default constructor which creates an object that can be
RyoheiHagimoto 0:0e0631af0305 301 WImageBuffer() : WImage<T>(0) {}
RyoheiHagimoto 0:0e0631af0305 302
RyoheiHagimoto 0:0e0631af0305 303 WImageBuffer(int width, int height, int nchannels) : WImage<T>(0) {
RyoheiHagimoto 0:0e0631af0305 304 Allocate(width, height, nchannels);
RyoheiHagimoto 0:0e0631af0305 305 }
RyoheiHagimoto 0:0e0631af0305 306
RyoheiHagimoto 0:0e0631af0305 307 // Constructor which takes ownership of a given IplImage so releases
RyoheiHagimoto 0:0e0631af0305 308 // the image on destruction.
RyoheiHagimoto 0:0e0631af0305 309 explicit WImageBuffer(IplImage* img) : WImage<T>(img) {}
RyoheiHagimoto 0:0e0631af0305 310
RyoheiHagimoto 0:0e0631af0305 311 // Allocate an image. Does nothing if current size is the same as
RyoheiHagimoto 0:0e0631af0305 312 // the new size.
RyoheiHagimoto 0:0e0631af0305 313 void Allocate(int width, int height, int nchannels);
RyoheiHagimoto 0:0e0631af0305 314
RyoheiHagimoto 0:0e0631af0305 315 // Set the data to point to an image, releasing the old data
RyoheiHagimoto 0:0e0631af0305 316 void SetIpl(IplImage* img) {
RyoheiHagimoto 0:0e0631af0305 317 ReleaseImage();
RyoheiHagimoto 0:0e0631af0305 318 WImage<T>::SetIpl(img);
RyoheiHagimoto 0:0e0631af0305 319 }
RyoheiHagimoto 0:0e0631af0305 320
RyoheiHagimoto 0:0e0631af0305 321 // Clone an image which reallocates the image if of a different dimension.
RyoheiHagimoto 0:0e0631af0305 322 void CloneFrom(const WImage<T>& src) {
RyoheiHagimoto 0:0e0631af0305 323 Allocate(src.Width(), src.Height(), src.Channels());
RyoheiHagimoto 0:0e0631af0305 324 CopyFrom(src);
RyoheiHagimoto 0:0e0631af0305 325 }
RyoheiHagimoto 0:0e0631af0305 326
RyoheiHagimoto 0:0e0631af0305 327 ~WImageBuffer() {
RyoheiHagimoto 0:0e0631af0305 328 ReleaseImage();
RyoheiHagimoto 0:0e0631af0305 329 }
RyoheiHagimoto 0:0e0631af0305 330
RyoheiHagimoto 0:0e0631af0305 331 // Release the image if it isn't null.
RyoheiHagimoto 0:0e0631af0305 332 void ReleaseImage() {
RyoheiHagimoto 0:0e0631af0305 333 if (WImage<T>::image_) {
RyoheiHagimoto 0:0e0631af0305 334 IplImage* image = WImage<T>::image_;
RyoheiHagimoto 0:0e0631af0305 335 cvReleaseImage(&image);
RyoheiHagimoto 0:0e0631af0305 336 WImage<T>::SetIpl(0);
RyoheiHagimoto 0:0e0631af0305 337 }
RyoheiHagimoto 0:0e0631af0305 338 }
RyoheiHagimoto 0:0e0631af0305 339
RyoheiHagimoto 0:0e0631af0305 340 bool IsNull() const {return WImage<T>::image_ == NULL; }
RyoheiHagimoto 0:0e0631af0305 341
RyoheiHagimoto 0:0e0631af0305 342 private:
RyoheiHagimoto 0:0e0631af0305 343 // Disallow copy and assignment
RyoheiHagimoto 0:0e0631af0305 344 WImageBuffer(const WImageBuffer&);
RyoheiHagimoto 0:0e0631af0305 345 void operator=(const WImageBuffer&);
RyoheiHagimoto 0:0e0631af0305 346 };
RyoheiHagimoto 0:0e0631af0305 347
RyoheiHagimoto 0:0e0631af0305 348 /** Like a WImageBuffer class but when the number of channels is known at compile time.
RyoheiHagimoto 0:0e0631af0305 349 */
RyoheiHagimoto 0:0e0631af0305 350 template<typename T, int C>
RyoheiHagimoto 0:0e0631af0305 351 class WImageBufferC : public WImageC<T, C>
RyoheiHagimoto 0:0e0631af0305 352 {
RyoheiHagimoto 0:0e0631af0305 353 public:
RyoheiHagimoto 0:0e0631af0305 354 typedef typename WImage<T>::BaseType BaseType;
RyoheiHagimoto 0:0e0631af0305 355 enum { kChannels = C };
RyoheiHagimoto 0:0e0631af0305 356
RyoheiHagimoto 0:0e0631af0305 357 // Default constructor which creates an object that can be
RyoheiHagimoto 0:0e0631af0305 358 WImageBufferC() : WImageC<T, C>(0) {}
RyoheiHagimoto 0:0e0631af0305 359
RyoheiHagimoto 0:0e0631af0305 360 WImageBufferC(int width, int height) : WImageC<T, C>(0) {
RyoheiHagimoto 0:0e0631af0305 361 Allocate(width, height);
RyoheiHagimoto 0:0e0631af0305 362 }
RyoheiHagimoto 0:0e0631af0305 363
RyoheiHagimoto 0:0e0631af0305 364 // Constructor which takes ownership of a given IplImage so releases
RyoheiHagimoto 0:0e0631af0305 365 // the image on destruction.
RyoheiHagimoto 0:0e0631af0305 366 explicit WImageBufferC(IplImage* img) : WImageC<T, C>(img) {}
RyoheiHagimoto 0:0e0631af0305 367
RyoheiHagimoto 0:0e0631af0305 368 // Allocate an image. Does nothing if current size is the same as
RyoheiHagimoto 0:0e0631af0305 369 // the new size.
RyoheiHagimoto 0:0e0631af0305 370 void Allocate(int width, int height);
RyoheiHagimoto 0:0e0631af0305 371
RyoheiHagimoto 0:0e0631af0305 372 // Set the data to point to an image, releasing the old data
RyoheiHagimoto 0:0e0631af0305 373 void SetIpl(IplImage* img) {
RyoheiHagimoto 0:0e0631af0305 374 ReleaseImage();
RyoheiHagimoto 0:0e0631af0305 375 WImageC<T, C>::SetIpl(img);
RyoheiHagimoto 0:0e0631af0305 376 }
RyoheiHagimoto 0:0e0631af0305 377
RyoheiHagimoto 0:0e0631af0305 378 // Clone an image which reallocates the image if of a different dimension.
RyoheiHagimoto 0:0e0631af0305 379 void CloneFrom(const WImageC<T, C>& src) {
RyoheiHagimoto 0:0e0631af0305 380 Allocate(src.Width(), src.Height());
RyoheiHagimoto 0:0e0631af0305 381 CopyFrom(src);
RyoheiHagimoto 0:0e0631af0305 382 }
RyoheiHagimoto 0:0e0631af0305 383
RyoheiHagimoto 0:0e0631af0305 384 ~WImageBufferC() {
RyoheiHagimoto 0:0e0631af0305 385 ReleaseImage();
RyoheiHagimoto 0:0e0631af0305 386 }
RyoheiHagimoto 0:0e0631af0305 387
RyoheiHagimoto 0:0e0631af0305 388 // Release the image if it isn't null.
RyoheiHagimoto 0:0e0631af0305 389 void ReleaseImage() {
RyoheiHagimoto 0:0e0631af0305 390 if (WImage<T>::image_) {
RyoheiHagimoto 0:0e0631af0305 391 IplImage* image = WImage<T>::image_;
RyoheiHagimoto 0:0e0631af0305 392 cvReleaseImage(&image);
RyoheiHagimoto 0:0e0631af0305 393 WImageC<T, C>::SetIpl(0);
RyoheiHagimoto 0:0e0631af0305 394 }
RyoheiHagimoto 0:0e0631af0305 395 }
RyoheiHagimoto 0:0e0631af0305 396
RyoheiHagimoto 0:0e0631af0305 397 bool IsNull() const {return WImage<T>::image_ == NULL; }
RyoheiHagimoto 0:0e0631af0305 398
RyoheiHagimoto 0:0e0631af0305 399 private:
RyoheiHagimoto 0:0e0631af0305 400 // Disallow copy and assignment
RyoheiHagimoto 0:0e0631af0305 401 WImageBufferC(const WImageBufferC&);
RyoheiHagimoto 0:0e0631af0305 402 void operator=(const WImageBufferC&);
RyoheiHagimoto 0:0e0631af0305 403 };
RyoheiHagimoto 0:0e0631af0305 404
RyoheiHagimoto 0:0e0631af0305 405 /** View into an image class which allows treating a subimage as an image or treating external data
RyoheiHagimoto 0:0e0631af0305 406 as an image
RyoheiHagimoto 0:0e0631af0305 407 */
RyoheiHagimoto 0:0e0631af0305 408 template<typename T> class WImageView : public WImage<T>
RyoheiHagimoto 0:0e0631af0305 409 {
RyoheiHagimoto 0:0e0631af0305 410 public:
RyoheiHagimoto 0:0e0631af0305 411 typedef typename WImage<T>::BaseType BaseType;
RyoheiHagimoto 0:0e0631af0305 412
RyoheiHagimoto 0:0e0631af0305 413 // Construct a subimage. No checks are done that the subimage lies
RyoheiHagimoto 0:0e0631af0305 414 // completely inside the original image.
RyoheiHagimoto 0:0e0631af0305 415 WImageView(WImage<T>* img, int c, int r, int width, int height);
RyoheiHagimoto 0:0e0631af0305 416
RyoheiHagimoto 0:0e0631af0305 417 // Refer to external data.
RyoheiHagimoto 0:0e0631af0305 418 // If not given width_step assumed to be same as width.
RyoheiHagimoto 0:0e0631af0305 419 WImageView(T* data, int width, int height, int channels, int width_step = -1);
RyoheiHagimoto 0:0e0631af0305 420
RyoheiHagimoto 0:0e0631af0305 421 // Refer to external data. This does NOT take ownership
RyoheiHagimoto 0:0e0631af0305 422 // of the supplied IplImage.
RyoheiHagimoto 0:0e0631af0305 423 WImageView(IplImage* img) : WImage<T>(img) {}
RyoheiHagimoto 0:0e0631af0305 424
RyoheiHagimoto 0:0e0631af0305 425 // Copy constructor
RyoheiHagimoto 0:0e0631af0305 426 WImageView(const WImage<T>& img) : WImage<T>(0) {
RyoheiHagimoto 0:0e0631af0305 427 header_ = *(img.Ipl());
RyoheiHagimoto 0:0e0631af0305 428 WImage<T>::SetIpl(&header_);
RyoheiHagimoto 0:0e0631af0305 429 }
RyoheiHagimoto 0:0e0631af0305 430
RyoheiHagimoto 0:0e0631af0305 431 WImageView& operator=(const WImage<T>& img) {
RyoheiHagimoto 0:0e0631af0305 432 header_ = *(img.Ipl());
RyoheiHagimoto 0:0e0631af0305 433 WImage<T>::SetIpl(&header_);
RyoheiHagimoto 0:0e0631af0305 434 return *this;
RyoheiHagimoto 0:0e0631af0305 435 }
RyoheiHagimoto 0:0e0631af0305 436
RyoheiHagimoto 0:0e0631af0305 437 protected:
RyoheiHagimoto 0:0e0631af0305 438 IplImage header_;
RyoheiHagimoto 0:0e0631af0305 439 };
RyoheiHagimoto 0:0e0631af0305 440
RyoheiHagimoto 0:0e0631af0305 441
RyoheiHagimoto 0:0e0631af0305 442 template<typename T, int C>
RyoheiHagimoto 0:0e0631af0305 443 class WImageViewC : public WImageC<T, C>
RyoheiHagimoto 0:0e0631af0305 444 {
RyoheiHagimoto 0:0e0631af0305 445 public:
RyoheiHagimoto 0:0e0631af0305 446 typedef typename WImage<T>::BaseType BaseType;
RyoheiHagimoto 0:0e0631af0305 447 enum { kChannels = C };
RyoheiHagimoto 0:0e0631af0305 448
RyoheiHagimoto 0:0e0631af0305 449 // Default constructor needed for vectors of views.
RyoheiHagimoto 0:0e0631af0305 450 WImageViewC();
RyoheiHagimoto 0:0e0631af0305 451
RyoheiHagimoto 0:0e0631af0305 452 virtual ~WImageViewC() {}
RyoheiHagimoto 0:0e0631af0305 453
RyoheiHagimoto 0:0e0631af0305 454 // Construct a subimage. No checks are done that the subimage lies
RyoheiHagimoto 0:0e0631af0305 455 // completely inside the original image.
RyoheiHagimoto 0:0e0631af0305 456 WImageViewC(WImageC<T, C>* img,
RyoheiHagimoto 0:0e0631af0305 457 int c, int r, int width, int height);
RyoheiHagimoto 0:0e0631af0305 458
RyoheiHagimoto 0:0e0631af0305 459 // Refer to external data
RyoheiHagimoto 0:0e0631af0305 460 WImageViewC(T* data, int width, int height, int width_step = -1);
RyoheiHagimoto 0:0e0631af0305 461
RyoheiHagimoto 0:0e0631af0305 462 // Refer to external data. This does NOT take ownership
RyoheiHagimoto 0:0e0631af0305 463 // of the supplied IplImage.
RyoheiHagimoto 0:0e0631af0305 464 WImageViewC(IplImage* img) : WImageC<T, C>(img) {}
RyoheiHagimoto 0:0e0631af0305 465
RyoheiHagimoto 0:0e0631af0305 466 // Copy constructor which does a shallow copy to allow multiple views
RyoheiHagimoto 0:0e0631af0305 467 // of same data. gcc-4.1.1 gets confused if both versions of
RyoheiHagimoto 0:0e0631af0305 468 // the constructor and assignment operator are not provided.
RyoheiHagimoto 0:0e0631af0305 469 WImageViewC(const WImageC<T, C>& img) : WImageC<T, C>(0) {
RyoheiHagimoto 0:0e0631af0305 470 header_ = *(img.Ipl());
RyoheiHagimoto 0:0e0631af0305 471 WImageC<T, C>::SetIpl(&header_);
RyoheiHagimoto 0:0e0631af0305 472 }
RyoheiHagimoto 0:0e0631af0305 473 WImageViewC(const WImageViewC<T, C>& img) : WImageC<T, C>(0) {
RyoheiHagimoto 0:0e0631af0305 474 header_ = *(img.Ipl());
RyoheiHagimoto 0:0e0631af0305 475 WImageC<T, C>::SetIpl(&header_);
RyoheiHagimoto 0:0e0631af0305 476 }
RyoheiHagimoto 0:0e0631af0305 477
RyoheiHagimoto 0:0e0631af0305 478 WImageViewC& operator=(const WImageC<T, C>& img) {
RyoheiHagimoto 0:0e0631af0305 479 header_ = *(img.Ipl());
RyoheiHagimoto 0:0e0631af0305 480 WImageC<T, C>::SetIpl(&header_);
RyoheiHagimoto 0:0e0631af0305 481 return *this;
RyoheiHagimoto 0:0e0631af0305 482 }
RyoheiHagimoto 0:0e0631af0305 483 WImageViewC& operator=(const WImageViewC<T, C>& img) {
RyoheiHagimoto 0:0e0631af0305 484 header_ = *(img.Ipl());
RyoheiHagimoto 0:0e0631af0305 485 WImageC<T, C>::SetIpl(&header_);
RyoheiHagimoto 0:0e0631af0305 486 return *this;
RyoheiHagimoto 0:0e0631af0305 487 }
RyoheiHagimoto 0:0e0631af0305 488
RyoheiHagimoto 0:0e0631af0305 489 protected:
RyoheiHagimoto 0:0e0631af0305 490 IplImage header_;
RyoheiHagimoto 0:0e0631af0305 491 };
RyoheiHagimoto 0:0e0631af0305 492
RyoheiHagimoto 0:0e0631af0305 493
RyoheiHagimoto 0:0e0631af0305 494 // Specializations for depth
RyoheiHagimoto 0:0e0631af0305 495 template<>
RyoheiHagimoto 0:0e0631af0305 496 inline int WImage<uchar>::Depth() const {return IPL_DEPTH_8U; }
RyoheiHagimoto 0:0e0631af0305 497 template<>
RyoheiHagimoto 0:0e0631af0305 498 inline int WImage<signed char>::Depth() const {return IPL_DEPTH_8S; }
RyoheiHagimoto 0:0e0631af0305 499 template<>
RyoheiHagimoto 0:0e0631af0305 500 inline int WImage<short>::Depth() const {return IPL_DEPTH_16S; }
RyoheiHagimoto 0:0e0631af0305 501 template<>
RyoheiHagimoto 0:0e0631af0305 502 inline int WImage<ushort>::Depth() const {return IPL_DEPTH_16U; }
RyoheiHagimoto 0:0e0631af0305 503 template<>
RyoheiHagimoto 0:0e0631af0305 504 inline int WImage<int>::Depth() const {return IPL_DEPTH_32S; }
RyoheiHagimoto 0:0e0631af0305 505 template<>
RyoheiHagimoto 0:0e0631af0305 506 inline int WImage<float>::Depth() const {return IPL_DEPTH_32F; }
RyoheiHagimoto 0:0e0631af0305 507 template<>
RyoheiHagimoto 0:0e0631af0305 508 inline int WImage<double>::Depth() const {return IPL_DEPTH_64F; }
RyoheiHagimoto 0:0e0631af0305 509
RyoheiHagimoto 0:0e0631af0305 510 template<typename T> inline WImage<T>::~WImage() {}
RyoheiHagimoto 0:0e0631af0305 511 template<typename T, int C> inline WImageC<T, C>::~WImageC() {}
RyoheiHagimoto 0:0e0631af0305 512
RyoheiHagimoto 0:0e0631af0305 513 template<typename T>
RyoheiHagimoto 0:0e0631af0305 514 inline void WImageBuffer<T>::Allocate(int width, int height, int nchannels)
RyoheiHagimoto 0:0e0631af0305 515 {
RyoheiHagimoto 0:0e0631af0305 516 if (IsNull() || WImage<T>::Width() != width ||
RyoheiHagimoto 0:0e0631af0305 517 WImage<T>::Height() != height || WImage<T>::Channels() != nchannels) {
RyoheiHagimoto 0:0e0631af0305 518 ReleaseImage();
RyoheiHagimoto 0:0e0631af0305 519 WImage<T>::image_ = cvCreateImage(cvSize(width, height),
RyoheiHagimoto 0:0e0631af0305 520 WImage<T>::Depth(), nchannels);
RyoheiHagimoto 0:0e0631af0305 521 }
RyoheiHagimoto 0:0e0631af0305 522 }
RyoheiHagimoto 0:0e0631af0305 523
RyoheiHagimoto 0:0e0631af0305 524 template<typename T, int C>
RyoheiHagimoto 0:0e0631af0305 525 inline void WImageBufferC<T, C>::Allocate(int width, int height)
RyoheiHagimoto 0:0e0631af0305 526 {
RyoheiHagimoto 0:0e0631af0305 527 if (IsNull() || WImage<T>::Width() != width || WImage<T>::Height() != height) {
RyoheiHagimoto 0:0e0631af0305 528 ReleaseImage();
RyoheiHagimoto 0:0e0631af0305 529 WImageC<T, C>::SetIpl(cvCreateImage(cvSize(width, height),WImage<T>::Depth(), C));
RyoheiHagimoto 0:0e0631af0305 530 }
RyoheiHagimoto 0:0e0631af0305 531 }
RyoheiHagimoto 0:0e0631af0305 532
RyoheiHagimoto 0:0e0631af0305 533 template<typename T>
RyoheiHagimoto 0:0e0631af0305 534 WImageView<T>::WImageView(WImage<T>* img, int c, int r, int width, int height)
RyoheiHagimoto 0:0e0631af0305 535 : WImage<T>(0)
RyoheiHagimoto 0:0e0631af0305 536 {
RyoheiHagimoto 0:0e0631af0305 537 header_ = *(img->Ipl());
RyoheiHagimoto 0:0e0631af0305 538 header_.imageData = reinterpret_cast<char*>((*img)(c, r));
RyoheiHagimoto 0:0e0631af0305 539 header_.width = width;
RyoheiHagimoto 0:0e0631af0305 540 header_.height = height;
RyoheiHagimoto 0:0e0631af0305 541 WImage<T>::SetIpl(&header_);
RyoheiHagimoto 0:0e0631af0305 542 }
RyoheiHagimoto 0:0e0631af0305 543
RyoheiHagimoto 0:0e0631af0305 544 template<typename T>
RyoheiHagimoto 0:0e0631af0305 545 WImageView<T>::WImageView(T* data, int width, int height, int nchannels, int width_step)
RyoheiHagimoto 0:0e0631af0305 546 : WImage<T>(0)
RyoheiHagimoto 0:0e0631af0305 547 {
RyoheiHagimoto 0:0e0631af0305 548 cvInitImageHeader(&header_, cvSize(width, height), WImage<T>::Depth(), nchannels);
RyoheiHagimoto 0:0e0631af0305 549 header_.imageData = reinterpret_cast<char*>(data);
RyoheiHagimoto 0:0e0631af0305 550 if (width_step > 0) {
RyoheiHagimoto 0:0e0631af0305 551 header_.widthStep = width_step;
RyoheiHagimoto 0:0e0631af0305 552 }
RyoheiHagimoto 0:0e0631af0305 553 WImage<T>::SetIpl(&header_);
RyoheiHagimoto 0:0e0631af0305 554 }
RyoheiHagimoto 0:0e0631af0305 555
RyoheiHagimoto 0:0e0631af0305 556 template<typename T, int C>
RyoheiHagimoto 0:0e0631af0305 557 WImageViewC<T, C>::WImageViewC(WImageC<T, C>* img, int c, int r, int width, int height)
RyoheiHagimoto 0:0e0631af0305 558 : WImageC<T, C>(0)
RyoheiHagimoto 0:0e0631af0305 559 {
RyoheiHagimoto 0:0e0631af0305 560 header_ = *(img->Ipl());
RyoheiHagimoto 0:0e0631af0305 561 header_.imageData = reinterpret_cast<char*>((*img)(c, r));
RyoheiHagimoto 0:0e0631af0305 562 header_.width = width;
RyoheiHagimoto 0:0e0631af0305 563 header_.height = height;
RyoheiHagimoto 0:0e0631af0305 564 WImageC<T, C>::SetIpl(&header_);
RyoheiHagimoto 0:0e0631af0305 565 }
RyoheiHagimoto 0:0e0631af0305 566
RyoheiHagimoto 0:0e0631af0305 567 template<typename T, int C>
RyoheiHagimoto 0:0e0631af0305 568 WImageViewC<T, C>::WImageViewC() : WImageC<T, C>(0) {
RyoheiHagimoto 0:0e0631af0305 569 cvInitImageHeader(&header_, cvSize(0, 0), WImage<T>::Depth(), C);
RyoheiHagimoto 0:0e0631af0305 570 header_.imageData = reinterpret_cast<char*>(0);
RyoheiHagimoto 0:0e0631af0305 571 WImageC<T, C>::SetIpl(&header_);
RyoheiHagimoto 0:0e0631af0305 572 }
RyoheiHagimoto 0:0e0631af0305 573
RyoheiHagimoto 0:0e0631af0305 574 template<typename T, int C>
RyoheiHagimoto 0:0e0631af0305 575 WImageViewC<T, C>::WImageViewC(T* data, int width, int height, int width_step)
RyoheiHagimoto 0:0e0631af0305 576 : WImageC<T, C>(0)
RyoheiHagimoto 0:0e0631af0305 577 {
RyoheiHagimoto 0:0e0631af0305 578 cvInitImageHeader(&header_, cvSize(width, height), WImage<T>::Depth(), C);
RyoheiHagimoto 0:0e0631af0305 579 header_.imageData = reinterpret_cast<char*>(data);
RyoheiHagimoto 0:0e0631af0305 580 if (width_step > 0) {
RyoheiHagimoto 0:0e0631af0305 581 header_.widthStep = width_step;
RyoheiHagimoto 0:0e0631af0305 582 }
RyoheiHagimoto 0:0e0631af0305 583 WImageC<T, C>::SetIpl(&header_);
RyoheiHagimoto 0:0e0631af0305 584 }
RyoheiHagimoto 0:0e0631af0305 585
RyoheiHagimoto 0:0e0631af0305 586 // Construct a view into a region of an image
RyoheiHagimoto 0:0e0631af0305 587 template<typename T>
RyoheiHagimoto 0:0e0631af0305 588 WImageView<T> WImage<T>::View(int c, int r, int width, int height) {
RyoheiHagimoto 0:0e0631af0305 589 return WImageView<T>(this, c, r, width, height);
RyoheiHagimoto 0:0e0631af0305 590 }
RyoheiHagimoto 0:0e0631af0305 591
RyoheiHagimoto 0:0e0631af0305 592 template<typename T, int C>
RyoheiHagimoto 0:0e0631af0305 593 WImageViewC<T, C> WImageC<T, C>::View(int c, int r, int width, int height) {
RyoheiHagimoto 0:0e0631af0305 594 return WImageViewC<T, C>(this, c, r, width, height);
RyoheiHagimoto 0:0e0631af0305 595 }
RyoheiHagimoto 0:0e0631af0305 596
RyoheiHagimoto 0:0e0631af0305 597 //! @} core
RyoheiHagimoto 0:0e0631af0305 598
RyoheiHagimoto 0:0e0631af0305 599 } // end of namespace
RyoheiHagimoto 0:0e0631af0305 600
RyoheiHagimoto 0:0e0631af0305 601 #endif // __cplusplus
RyoheiHagimoto 0:0e0631af0305 602
RyoheiHagimoto 0:0e0631af0305 603 #endif