Subversion Repositories seema-scanner

Rev

Rev 123 | Rev 125 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 123 Rev 124
Line 1... Line 1...
1
#include "AlgorithmLineShift.h"
1
#include "AlgorithmLineShift.h"
2
#include <cmath>
2
#include <cmath>
3
#include "cvtools.h"
3
#include "cvtools.h"
4
 
4
 
5
#include <opencv2/imgproc.hpp>
5
#include <opencv2/imgproc/imgproc.hpp>
6
 
6
 
7
#ifndef log2f
7
#ifndef log2f
8
#define log2f(x) (log(x)/log(2.0))
8
#define log2f(x) (log(x)/log(2.0))
9
#endif
9
#endif
10
 
10
 
Line 116... Line 116...
116
        patterns.push_back(patternInv);
116
        patterns.push_back(patternInv);
117
    }
117
    }
118
 
118
 
119
    // line shifts
119
    // line shifts
120
    for(unsigned int p=0; p<nLineShifts; p++){
120
    for(unsigned int p=0; p<nLineShifts; p++){
121
        cv::Mat pattern(1, screenCols, CV_8UC3, cv::Vec3b(0, 0, 0));
121
        cv::Mat pattern(1, screenCols, CV_8UC3, cv::Scalar(0));
122
 
122
 
123
        for(unsigned int j=p; j<screenCols; j+= nLineShifts)
123
        for(unsigned int j=p; j<screenCols; j+= nLineShifts)
124
            pattern.at<cv::Vec3b>(0, j) = cv::Vec3b(255, 255, 255);
124
            pattern.at<cv::Vec3b>(0, j) = cv::Vec3b(255, 255, 255);
125
 
125
 
126
        patterns.push_back(pattern);
126
        patterns.push_back(pattern);
Line 155... Line 155...
155
                           + (img.at<cv::Vec3b>(y1, x0)[2] * (1.f - a) + img.at<cv::Vec3b>(y1, x1)[2] * a) * c);
155
                           + (img.at<cv::Vec3b>(y1, x0)[2] * (1.f - a) + img.at<cv::Vec3b>(y1, x1)[2] * a) * c);
156
 
156
 
157
    return cv::Vec3b(b, g, r);
157
    return cv::Vec3b(b, g, r);
158
}
158
}
159
 
159
 
160
void getlineCenters(const cv::Mat& linesScanLine, const cv::Mat& codeScanLine, std::vector<cv::Vec4i>& lineCenters){
160
void getlineCenters(const cv::Mat& linesScanLine, const cv::Mat& codeScanLine, std::vector<cv::Vec2f>& lineCenters){
161
 
161
 
162
    int nCols = linesScanLine.cols;
162
    int nCols = linesScanLine.cols;
163
 
163
 
164
    // fourth order derivative filtering
164
    // fourth order derivative filtering
165
    cv::Mat der(1, nCols, CV_8U);
165
    cv::Mat der(1, nCols, CV_8U);
Line 169... Line 169...
169
 
169
 
170
    for(int i=0; i<nCols; i++){
170
    for(int i=0; i<nCols; i++){
171
 
171
 
172
        if(der.at<unsigned char>(0, i) > 0 && der.at<unsigned char>(0, i+1) < 0){
172
        if(der.at<unsigned char>(0, i) > 0 && der.at<unsigned char>(0, i+1) < 0){
173
 
173
 
174
            lineCenters.push_back(i, codeScanLine.at<unsigned char>(0, i));
174
            lineCenters.push_back(cv::Vec2f(i, codeScanLine.at<unsigned char>(0, i)));
175
            // TODO: subpixel interpolation, non-max suppression
175
            // TODO: subpixel interpolation, non-max suppression
176
        }
176
        }
177
 
177
 
178
    }
178
    }
179
 
179
 
Line 274... Line 274...
274
    for(int i=0; i<nGrayBits; i++){
274
    for(int i=0; i<nGrayBits; i++){
275
        cv::Mat temp, bit0, bit1;
275
        cv::Mat temp, bit0, bit1;
276
 
276
 
277
        cv::compare(frames0GrayCode[i*2], frames0GrayCode[i*2+1], temp, cv::CMP_GT);
277
        cv::compare(frames0GrayCode[i*2], frames0GrayCode[i*2+1], temp, cv::CMP_GT);
278
        temp.convertTo(bit0, CV_32S, 1.0/255.0);
278
        temp.convertTo(bit0, CV_32S, 1.0/255.0);
279
        cv::add(code0Gray, bit0*twopowi(Nbits-i-1), code0Gray, cv::noArray(), CV_32S);
279
        cv::add(code0Gray, bit0*twopowi(nGrayBits-i-1), code0Gray, cv::noArray(), CV_32S);
280
 
280
 
281
        cv::compare(frames1GrayCode[i*2], frames1GrayCode[i*2+1], temp, cv::CMP_GT);
281
        cv::compare(frames1GrayCode[i*2], frames1GrayCode[i*2+1], temp, cv::CMP_GT);
282
        temp.convertTo(bit1, CV_32S, 1.0/255.0);
282
        temp.convertTo(bit1, CV_32S, 1.0/255.0);
283
        cv::add(code1Gray, bit1*twopowi(Nbits-i-1), code1Gray, cv::noArray(), CV_32S);
283
        cv::add(code1Gray, bit1*twopowi(nGrayBits-i-1), code1Gray, cv::noArray(), CV_32S);
284
    }
284
    }
285
 
285
 
286
    // set occluded pixels to -1
286
    // set occluded pixels to -1
287
    for(int r=0; r<frameRectRows; r++){
287
    for(int r=0; r<frameRectRows; r++){
288
        for(int c=0; c<frameRectCols; c++){
288
        for(int c=0; c<frameRectCols; c++){