main.cpp

Small test program for different template types for Mat_ - Jukka Holappa, 2012-03-20 10:29 pm

Download (1001 Bytes)

 
1
#include <iostream>
2
#include <opencv2/core/core.hpp>
3
4
template<class T>
5
void testType(cv::Size sz, T value = T())
6
{
7
        cv::Mat_<T> m(sz);
8
9
        std::cout << "Size: " << m.size().width << " x " << m.size().height << " channels " << m.channels() << " element size: " << m.elemSize() << " step1: " << m.step1() << " total: " << m.total() << std::endl;
10
        std::cout << "Allocated memory: " << reinterpret_cast<const unsigned char *>(&(*m.end())) - reinterpret_cast<const unsigned char *>(&(*m.begin())) << " bytes" << std::endl;
11
12
        for (int y = 0; y < sz.height; ++y)
13
        {
14
                for (int x = 0; x < sz.width; ++x)
15
                {
16
                        std::cout << "Pointer to element " << x << ", " << y << ": " << reinterpret_cast<unsigned long long>(&m(y, x)) << std::endl;
17
                        m(y, x) = value;
18
                }
19
        }
20
}
21
22
int main(int argc, char **argv)
23
{
24
        std::vector<int *> memblocks;
25
26
        cv::Size size(2, 5);
27
        testType<float>(size);
28
        testType<cv::Vec3f>(size);
29
        testType<cv::Matx31f>(size);
30
        testType<cv::Matx41f>(size);
31
        testType<cv::Matx32f>(size);
32
33
        return 0;
34
}