debug.cpp

source showing bug - b b, 2012-01-21 01:06 am

Download (2 kB)

 
1
#include "opencv2/highgui/highgui.hpp"
2
#include "opencv2/core/core.hpp"
3
#include "opencv2/imgproc/imgproc.hpp"
4
5
#include <iostream>
6
#include <stdio.h>
7
8
#define MAXSTRING 50 // 50 chars enough?
9
10
using namespace cv;
11
using namespace std;
12
13
// Class to hold the perceptual chunks.
14
class percepUnit {
15
16
        public:
17
                Mat image; // percept itself
18
                Mat mask; // alpha channel
19
                int x1, y1; // close edges TODO change the below values to opencv types? (Point, Rect?)
20
                int w, h; // width / height of patch
21
        
22
                // constructor method
23
                percepUnit(Mat ROI, Mat alpha, int ix, int iy, int iw, int ih) {
24
                        ROI.copyTo(image); // make copies since args are refs!!
25
                        alpha.copyTo(mask);
26
                        x1 = ix;
27
                        y1 = iy;
28
                        w = iw;        
29
                        h = ih;
30
                }
31
32
                // Destructor
33
                ~percepUnit() {
34
                        // Free memory
35
                        image.release();
36
                        mask.release();
37
                }
38
};
39
40
// pixel by pixel offset copy of perceptUnit into larger image.
41
// TODO try and dump the dimentions of the image and mask files, and also dump the bounding box sizes to check if they match.
42
int copyPercept(percepUnit &unit, Mat &dest) {
43
44
        // Loop through pixels in percept image
45
        for( int y = 0; y < unit.image.rows; y++ ) {
46
        for( int x = 0; x < unit.image.cols; x++ ) {
47
                        // Make sure this pixel is in the mask.
48
                        if (unit.mask.at<char>(y,x) != 0) {
49
                                // get pixels from src image:
50
                                Vec3b pixel = unit.image.at<Vec3b>(y,x); // Vec3b is a 3 element vector of unsigned chars.
51
52
                                // set pixels in dest image (offset for this percept)
53
                                dest.at<Vec3b>(y+unit.y1,x+unit.x1) = pixel;
54
                        }
55
                }
56
        }
57
58
        return(0);
59
}
60
61
int main(int argc, char* argv[])
62
{
63
        Mat reconstruction2 = Mat(1080,1920, CV_8UC3, Scalar(255,255,255)); // white background
64
65
        for (int s=1070; s<1920; s++) {
66
67
                Mat tmpImage = Mat(s,s,  CV_8UC3, Scalar(0,0,0));
68
                Mat tmpMask = Mat(s,s,  CV_8UC1, Scalar(255,255,255));
69
                percepUnit tmpUnit = percepUnit(tmpImage, tmpMask, 0, 0, s, s);
70
71
                cout << "size: " << s << endl;
72
                reconstruction2 = copyPercept(tmpUnit, reconstruction2);
73
        }
74
75
        imwrite("reconstruction2.png",reconstruction2);
76
77
        exit(0); // this was "return" before, did that not clean up anything?
78
}