Appender::Appender() { _id = -1; _layout = comlog_get_def_layout(); _core_debug("init layout %lx", _layout); _mask = 0; _open = 1; resetMask(); pthread_mutex_init(&_lock, NULL); _bkappender = NULL; setLayout(NULL); }
void ChromaticMask::setParams(unsigned int mc, unsigned int nc, double threshProb, aruco::CameraParameters CP, aruco::BoardConfiguration BC, vector<cv::Point3f> corners) { _classifiers.resize(mc*nc); for(unsigned int i=0; i<_classifiers.size(); i++) _classifiers[i].setProb(threshProb); _mc = mc; _nc = nc; _threshProb = threshProb; _cell_neighbours.resize(mc*nc); int idx_=0; //cout << "STD PRINTING!!" << endl; //SGJ: revisar, no engo claro sepa bien que es i y j y los puedo estar confundiendo!!! for(unsigned int j=0; j<nc; j++) for(unsigned int i=0; i<mc; i++,idx_++) { _centers.push_back(cv::Point2f(i+0.5, j+0.5)); for(unsigned int nj=max(j-1,(unsigned int)0); nj<min(mc,j+1); nj++) { for(unsigned int ni=max(i-1,(unsigned int)0); ni<min(mc,i+1); ni++) { size_t tidx=nj*mc+ni; _cell_neighbours[idx_].push_back(tidx); } } } //cout << "STD PRINTING!!" << endl; //deterimne the idx of the neighbours _BD.getMarkerDetector().setThresholdParams(35,7); _BD.getMarkerDetector().enableErosion(false); _BD.getMarkerDetector().setCornerRefinementMethod(aruco::MarkerDetector::LINES); _BD.setYPerpendicular(false); _BD.setParams(BC, CP); _objCornerPoints = corners; _CP = CP; //cout << "STD PRINTING!!" << endl; _pixelsVector.clear(); for(unsigned int i=0; i<CP.CamSize.height/2; i++) for(unsigned int j=0; j<CP.CamSize.width/2; j++) _pixelsVector.push_back( cv::Point2f(2*j,2*i) ); //cout << "STD PRINTING!!" << endl; resetMask(); //cout << "cam size: " << CP.CamSize.height << " " << CP.CamSize.width << endl; _cellMap = cv::Mat(CP.CamSize.height, CP.CamSize.width, CV_8UC1, cv::Scalar::all(0)); _canonicalPos = cv::Mat(CP.CamSize.height, CP.CamSize.width, CV_8UC2); _cellCenters.resize(_classifiers.size()); for(unsigned int i=0; i<mc; i++) { for(unsigned int j=0; j<nc; j++) { _cellCenters[i*mc+j].x = ((2*i+1)*_cellSize)/2.; _cellCenters[i*mc+j].y = ((2*j+1)*_cellSize)/2.; } } }
void ChromaticMask::classify(const cv::Mat& in, const aruco::Board &board) { calculateGridImage(board); resetMask(); for(unsigned int i=0; i<in.rows; i++) { const uchar* in_ptr = in.ptr<uchar>(i); const uchar* _cellMap_ptr = _cellMap.ptr<uchar>(i); for(unsigned int j=0; j<in.cols; j++) { uchar idx = _cellMap_ptr[j]; if(idx!=0) { // considering neighbours // float prob=0.0; // float totalW = 0.0; // cv::Point2d pix(i,j); // for(uint k=0; k<_classifiers.size()-17; k++) { // float w = 1./(1.+getDistance(pix,k)); // totalW += w; // prob += w*_classifiers[k].getProb(in_ptr[j] ); // } // prob /= totalW; // if(prob > _threshProb) _mask.at<uchar>(i,j)=1; // not considering neighbours if(_classifiers[idx-1].classify( in.at<uchar>(i,j) )) _mask.at<uchar>(i,j)=1; // if(_classifiers[idx-1].probConj[ in.at<uchar>(i,j)]>_threshProb ) _mask.at<uchar>(i,j)=1; } } } // apply closing to mask cv::Mat maskClose; cv::Mat element = cv::getStructuringElement(cv::MORPH_RECT, cv::Size(3,3)); cv::morphologyEx(_mask, maskClose, CV_MOP_CLOSE, element); _mask = maskClose; }