void Labeler::convert2Example(const Instance* pInstance, Example& exam) { exam.clear(); const vector<string> &label1s = pInstance->label1s; const vector<string> &label2s = pInstance->label2s; int curInstSize = label1s.size(); for (int i = 0; i < curInstSize; ++i) { string orcale1 = label1s[i]; string orcale2 = label2s[i]; if (orcale2.length() > 2) orcale2 = orcale2.substr(2); int numLabel2s = m_label2Alphabet.size(); vector<int> curlabel2s; for (int j = 0; j < numLabel2s; ++j) { string str = m_label2Alphabet.from_id(j); if (str.compare(orcale2) == 0) curlabel2s.push_back(1); else curlabel2s.push_back(0); } exam.m_label2s.push_back(curlabel2s); Feature feat; extractFeature(feat, pInstance, i); exam.m_features.push_back(feat); } }
void Labeler::convert2Example(const Instance* pInstance, Example& exam) { exam.clear(); const string &label = pInstance->label; const vector<vector<string> > &words = pInstance->words; const vector<vector<vector<string> > > &chars = pInstance->chars; int numLabels = m_labelAlphabet.size(); for (int j = 0; j < numLabels; ++j) { string str = m_labelAlphabet.from_id(j); if (str.compare(label) == 0) exam.m_labels.push_back(1); else exam.m_labels.push_back(0); } int curInstSize = words.size(); for (int i = 0; i < curInstSize; ++i) { Feature feat; extractFeature(feat, pInstance, i); exam.m_features.push_back(feat); } if (m_linearfeat > 0) { vector<string> linear_features; extractLinearFeatures(linear_features, pInstance); for (int i = 0; i < linear_features.size(); i++) { int curFeatId = m_featAlphabet.from_string(linear_features[i]); if (curFeatId >= 0) exam.m_linears.push_back(curFeatId); } } }
int PlateJudge::plateJudge(const Mat &inMat, int &result) { Mat features; extractFeature(inMat, features); float response = svm_->predict(features); result = (int)response; return 0; }
int HaarFeature::extractOneTypeFeatures45(int is_extract_feature, HaarFeatureInfoT &info, float *pt_feature) { int type = info.type; int L_r = feature_sizes[type].x; int R_r = feature_sizes[type].y; double inv_r = feature_inv_ratio[type] * 2; CB_PointT image_size = {template_w, template_h}; info.pos1.y = FEATURE_MARGIN; while (info.pos1.y < template_h - 1) { info.pos1.x = FEATURE_MARGIN; while (info.pos1.x < template_w - 1) { info.size.y = 2; while (info.pos1.x + R_r * info.size.y < template_w) { info.size.x = 2; while (info.pos1.x - L_r * info.size.x > 0) { CB_SlantT slant = {info.pos1.x, info.pos1.y, L_r * info.size.x, R_r * info.size.y}; CB_RectangleT rect; int result = slantToRect(slant, rect, image_size); if (result == 0) { info.size.x += HAAR_SCALE_STEP_X; continue; } if (is_extract_feature == 0) { info.inv_area = INV_AREA_R / (info.size.x * info.size.y * inv_r); pt_feature_infos[feature_count] = info; } else if (is_extract_feature > 0) { *(pt_feature + feature_count) = extractFeature(pt_feature_infos[feature_count]); } feature_count++; info.size.x += HAAR_SCALE_STEP_X; } info.size.y += HAAR_SCALE_STEP_Y; } info.pos1.x += HAAR_SHIFT_STEP_X; } info.pos1.y += HAAR_SHIFT_STEP_Y; } return feature_count; }
//! 设置车牌图像的置信度 //! 返回值,0代表是车牌,其他值代表不是 int PlateJudge::plateSetScore(CPlate& plate) { Mat features; extractFeature(plate.getPlateMat(), features); float score = svm_->predict(features, noArray(), cv::ml::StatModel::Flags::RAW_OUTPUT); // score值代表离margin的距离,小于0代表是车牌,大于0代表不是车牌 // 当小于0时,值越小代表是车牌的概率越大 plate.setPlateScore(score); if (score < 0) return 0; else return -1; }
void classifierSVM(Mat& trainData, Mat& labelsTrain, vector<string> trainImgName, vector<string> testImgName, string kernelFunction, Mat& resultTrain, Mat& resultTest) { Mat trainFeatureData(0,1764, CV_32FC1); Mat testFeatureData(0,1764, CV_32FC1); string predictTrainFeatureVector="./result/PredictTrain-Features-LBP.txt"; string predictTestFeatureVector="./result/PredictTest-Features-LBP.txt"; stringstream predictTrainDataTxt; stringstream predictTestDataTxt; SVM::Params params; params.svmType = SVM::C_SVC;//C_SVC用于n类分类问题 if( kernelFunction == "LINEAR" ) params.kernelType = SVM::LINEAR; if( kernelFunction == "RBF" ) params.kernelType = SVM::RBF; Ptr<SVM> svm = SVM::create(params); svm->train( trainData , ROW_SAMPLE , labelsTrain ); /*----------------Predict traindata------------------*/ // Mat resultTrain; // 输出分类结果 trainFeatureData=extractFeature(trainImgName); WriteData(predictTrainFeatureVector, trainFeatureData); predictTrainDataTxt<<"./result/PredictTrain-LBP-SVM-"<<kernelFunction<<".txt"; svm->predict(trainFeatureData, resultTrain); WriteData(predictTrainDataTxt.str(), resultTrain); /*----------------Predict testdata-------------------*/ // Mat resultTest; // 输出分类结果 testFeatureData=extractFeature(testImgName); WriteData(predictTestFeatureVector, testFeatureData); predictTestDataTxt<<"./result/PredictTest-LBP-SVM-"<<kernelFunction<<".txt"; svm->predict(testFeatureData, resultTest); WriteData(predictTestDataTxt.str(), resultTest); }
void GeoJson::extractLayer(const rapidjson::Value& _in, Layer& _out, const MapTile& _tile) { const auto& featureIter = _in.FindMember("features"); if (featureIter == _in.MemberEnd()) { logMsg("ERROR: GeoJSON missing 'features' member\n"); return; } const auto& features = featureIter->value; for (auto featureJson = features.Begin(); featureJson != features.End(); ++featureJson) { _out.features.emplace_back(); extractFeature(*featureJson, _out.features.back(), _tile); } }
void ImageProcess::run() { switch(processStep) { case 1: //提取特征 extractFeature(); break; case 2: //匹配特征 matchFeature(); break; case 3: //对齐影像 alignImage(); break; } }
ControlWidget::ControlWidget(MainWindow* mainWin) : QDockWidget("Control Widget", (QWidget*)mainWin) { this->mainWin = mainWin; // set up the UI ui.setupUi(this); ui.checkBoxRoadTypeHighway->setChecked(true); ui.checkBoxRoadTypeBoulevard->setChecked(true); ui.checkBoxRoadTypeAvenue->setChecked(true); ui.checkBoxRoadTypeLocalStreet->setChecked(true); // register the event handlers connect(ui.checkBoxRoadTypeHighway, SIGNAL(stateChanged(int)), this, SLOT(showRoad(int))); connect(ui.checkBoxRoadTypeBoulevard, SIGNAL(stateChanged(int)), this, SLOT(showRoad(int))); connect(ui.checkBoxRoadTypeAvenue, SIGNAL(stateChanged(int)), this, SLOT(showRoad(int))); connect(ui.checkBoxRoadTypeLocalStreet, SIGNAL(stateChanged(int)), this, SLOT(showRoad(int))); connect(ui.pushButtonExtractFeature, SIGNAL(clicked()), this, SLOT(extractFeature())); hide(); }
void QueryExecutor::execute(HitCollectorPtr& pCollector, ScorerPtr& pScorer, const QueryTracerPtr& pTracer) { //TODO: allocate from mempool MatchedDocSet machedDocs(m_pPool, DEFAULT_MATCHED_DOC_BUFFER_SIZE, size()); machedDocs.setTracer(pTracer); QueryFeature queryFeature; queryFeature.reserve(size()); extractFeature(queryFeature); pScorer->beginQuery(m_pFeatureProvider, queryFeature); while (advance(machedDocs) > 0) { FX_TRACE("Matched doc count: [%u]", (uint32_t)machedDocs.size()); pScorer->score(machedDocs); pCollector->collect(machedDocs); machedDocs.reset(); } pScorer->endQuery(); }
int HaarFeature::extractOneTypeFeatures(int is_extract_feature, HaarFeatureInfoT &info, float *pt_feature) { int type = info.type; int x_r = feature_sizes[type].x; int y_r = feature_sizes[type].y; double inv_r = feature_inv_ratio[type]; info.pos1.y = FEATURE_MARGIN; while (info.pos1.y < template_h - 1) { info.pos1.x = FEATURE_MARGIN; while (info.pos1.x < template_w - 1) { info.size.y = 2; while (info.pos1.y + y_r * info.size.y - 1 < template_h - FEATURE_MARGIN) { info.size.x = 2; while (info.pos1.x + x_r * info.size.x - 1 < template_w - FEATURE_MARGIN) { if (is_extract_feature == 0) { info.inv_area = INV_AREA_R / (info.size.x * info.size.y * inv_r); pt_feature_infos[feature_count] = info; } else if (is_extract_feature > 0) { *(pt_feature + feature_count) = extractFeature(pt_feature_infos[feature_count]); } feature_count++; info.size.x += HAAR_SCALE_STEP_X; } info.size.y += HAAR_SCALE_STEP_Y; } info.pos1.x += HAAR_SHIFT_STEP_X; } info.pos1.y += HAAR_SHIFT_STEP_Y; } return feature_count; }