void XmlLoader::readGraphics(QDomElement const &graphic) { QDomNodeList graphicAttributes = graphic.childNodes(); int sizePictureX = 0; int sizePictureY = 0; for (unsigned i = 0; i < graphicAttributes.length(); ++i) { QDomElement type = graphicAttributes.at(i).toElement(); if (type.tagName() == "picture") { sizePictureX = (type.attribute("sizex", "")).toInt(); sizePictureY = (type.attribute("sizey", "")).toInt(); if (mReadFile) { if (mStrX + distanceFigure + sizePictureX >= sizeEmrtyRectX) { mStrY = mFloorY; mStrX = 0; } mDrift = QPoint(mStrX + distanceFigure, mStrY + distanceFigure); } else mDrift = QPoint(mScene->centerEmpty().x() - sizePictureX / 2, mScene->centerEmpty().y() - sizePictureY / 2); readPicture(type); } else if (type.tagName() == "labels") readLabels(type); else if (type.tagName() == "ports") readPorts(type); else qDebug() << "Incorrect graphics tag"; } if (mReadFile) { mFloorY = qMax(mFloorY, mDrift.y() + sizePictureY); mStrX = mDrift.x() + sizePictureX; } }
int GFFFile::init(int n) { if(!reading()) return errcode = 6; if(n == -1) n = initstages; if((n > 0) && !inited[0] && readHeader()) return errcode; if((n > 1) && !inited[1] && readLabels()) return errcode; if((n > 2) && !inited[2] && getStruct(0, topstruct)) return errcode; return errcode = 0; }
static void processGenomic(struct sqlConnection *conn, struct customPp *cpp, int colCount, char *formatType, boolean firstLineLabels, struct labeledFile *fileList, boolean report) /* Process three column file into chromGraph. Abort if * there's a problem. */ { char **row; struct chromGraph *cg; struct hash *chromHash = chromInfoHash(conn); struct labeledFile *fileEl; struct chromInfo *ci; int i; int rowCount = 0; Chopper chopper = getChopper(formatType); char *line; AllocArray(row, colCount); if (firstLineLabels) readLabels(cpp, 2, chopper, row, colCount, fileList); while ((line = customFactoryNextRealTilTrack(cpp)) != NULL) { chopper(line, row, colCount); char *chrom = cloneString(row[0]); int start = cppNeedNum(cpp, row, 1); ci = hashFindVal(chromHash, chrom); if (ci == NULL) cppAbort(cpp, "Chromosome %s not found in this assembly (%s).", chrom, sqlGetDatabase(conn)); if (start >= ci->size) { cppAbort(cpp, "Chromosome %s is %d bases long, but got coordinate %d.", chrom, ci->size, start); } else if (start < 0) { cppAbort(cpp, "Negative base position %d on chromosome %s.", start, chrom); } for (i=2, fileEl = fileList; i<colCount; ++i, fileEl = fileEl->next) { char *val = row[i]; if (val[0] != 0) { AllocVar(cg); cg->chrom = chrom; cg->chromStart = start; cg->val = cppNeedDouble(cpp, row, i); slAddHead(&fileEl->cgList, cg); } } ++rowCount; } if (report) printf("Read in %d markers and values in <i>chromosome base</i> format.<BR>\n", rowCount); }
bool RTABMapDBAdapter::readData(const std::vector<std::string> &dbPaths, Words &words, Labels &labels) { // Read data from databases std::map<int, std::map<int, std::unique_ptr<rtabmap::Signature>>> allSignatures; std::list<std::unique_ptr<Label>> allLabels; int dbId = 0; for (const auto &dbPath : dbPaths) { auto dbSignatures = readSignatures(dbPath); allSignatures.emplace(dbId, std::move(dbSignatures)); auto dbLabels = readLabels(dbPath, dbId, allSignatures); std::move(dbLabels.begin(), dbLabels.end(), std::back_inserter(allLabels)); dbId++; } std::cout << "Building Index for Words" << std::endl; std::list<std::unique_ptr<Word>> allWords = createWords(allSignatures); std::cout << "Total Number of words: " << allWords.size() << std::endl; long count = 0; for (const auto &word : allWords) { for (const auto &desc : word->getDescriptorsByDb()) { count += desc.second.rows; } } std::cout << "Total Number of descriptors: " << count << std::endl; allWords = clusterPointsInWords(allWords); count = 0; for (const auto &word : allWords) { for (const auto &desc : word->getDescriptorsByDb()) { count += desc.second.rows; } } std::cout << "Total Number of points: " << count << std::endl; words.putWords(std::move(allWords)); std::cout << "Building Index for Labels" << std::endl; labels.putLabels(std::move(allLabels)); return true; }
int main(int argc, char *argv[]) { if (argc != 4) { cout << "Usage: " << endl; cout << "ACCV2009.exe Folder imfn1 imfn2" << endl; return -1; } string folder = argv[1]; string imfn1 = argv[2]; string imfn2 = argv[3]; string outfolder = "../output"; _mkdir(outfolder.c_str()); Mat im1 = imread(folder + imfn1 + ".png", 1); Mat im2 = imread(folder + imfn2 + ".png", 1); int width = im1.cols; int height = im1.rows; //颜色空间转换 Mat im1_H, im1_S, im1_I; Mat im2_H, im2_S, im2_I; //CvtColorBGR2HSI(im1, im1_H, im1_S, im1_I); //CvtColorBGR2HSI(im2, im2_H, im2_S, im2_I); cv_CvtColorBGR2HSI(im1, im1_H, im1_S, im1_I); cv_CvtColorBGR2HSI(im2, im2_H, im2_S, im2_I); int sigmaS = 5; float sigmaR = 10; int minR = 800; vector<int> labels1(0), labels2(0); //#define RQ_DEBUG #ifdef RQ_DEBUG int regionum1, regionum2; DoMeanShift(im1, sigmaS, sigmaR, minR, labels1, regionum1); DoMeanShift(im2, sigmaS, sigmaR, minR, labels2, regionum2); cout << endl; saveLabels(labels1, width, height, outfolder+"/labels_" + imfn1 + ".txt"); saveLabels(labels2, width, height, outfolder+"/labels_" + imfn2 + ".txt"); #else int regionum1, regionum2; readLabels(outfolder+"/labels_" + imfn1 + ".txt", width, height, labels1, regionum1); readLabels(outfolder+"/labels_" + imfn2 + ".txt", width, height, labels2, regionum2); #endif string siftmatchfn = folder + "matches_sift.txt"; vector<Point2f> features1(0), features2(0); ReadSiftMatches(siftmatchfn, features1, features2); vector<vector<Point2f>> matches1(0), matches2(0); vector<vector<Point2f>> pixelTable2(0); ComputeRegionMatches(labels2, regionum2, width, features1, features2, matches1, matches2); cout << "all regions have matches." << endl << endl; //显示每个区域的matches : 显示一次就好 vector<float> DeltaH(0), DeltaS(0), DeltaI(0); RegionDeltaColor(im1_H, im2_H, matches1, matches2, DeltaH); RegionDeltaColor(im1_S, im2_S, matches1, matches2, DeltaS); RegionDeltaColor(im1_I, im2_I, matches1, matches2, DeltaI); Mat new_im2_H, new_im2_S, new_im2_I; CorrectColor(im2_H, labels2, DeltaH, new_im2_H); CorrectColor(im2_S, labels2, DeltaS, new_im2_S); CorrectColor(im2_I, labels2, DeltaI, new_im2_I); Mat new_im2; //CvtColorHSI2BGR(new_im2_H, new_im2_S, new_im2_I, new_im2); cv_CVtColorHSI2BGR(new_im2_H, new_im2_S, new_im2_I, new_im2); cout << "done." << endl; imshow("new im2", new_im2); waitKey(0); destroyAllWindows(); string savefn = outfolder + "/accv2009_" + imfn2 + ".png"; cout << "save " << savefn << endl; imwrite(savefn, new_im2); }
void processDb(struct sqlConnection *conn, struct customPp *cpp, int colCount, char *formatType, boolean firstLineLabels, struct labeledFile *fileList, char *table, char *query, char *aliasTable, char *aliasQuery, boolean report, boolean isSnpTable) /* Process two column input file into chromGraph. Treat first * column as a name to look up in bed-format table, which should * not be split. Return TRUE on success. */ { struct hash *hash = NULL; if (!isSnpTable) hash = tableToChromPosHash(conn, table, query); struct hash *aliasHash = NULL; char **row; int match = 0, total = 0; struct chromGraph *cg; struct chromPos *pos; if (!isSnpTable && report) printf("Loaded %d elements from %s table for mapping.<BR>\n", hash->elCount, table); if (aliasTable != NULL) { aliasHash = tableToAliasHash(conn, aliasTable, aliasQuery); if (report) printf("Loaded %d aliases from %s table as well.<BR>\n", aliasHash->elCount, aliasTable); } fflush(stdout); // trying to keep browser from timing out AllocArray(row, colCount); Chopper chopper = getChopper(formatType); char *line; AllocArray(row, colCount); if (firstLineLabels) readLabels(cpp, 1, chopper, row, colCount, fileList); while ((line = customFactoryNextRealTilTrack(cpp)) != NULL) { chopper(line, row, colCount); char *name = row[0]; char *marker = cloneString(name); touppers(name); ++total; if (isSnpTable) pos = snpIndexLookup(conn, table, query, name); else { pos = hashFindVal(hash, name); if (pos == NULL && aliasHash != NULL) { name = hashFindVal(aliasHash, name); if (name != NULL) pos = hashFindVal(hash, name); } } if (pos != NULL) { int i; struct labeledFile *fileEl; ++match; for (i=1, fileEl=fileList; i < colCount; ++i, fileEl = fileEl->next) { char *val = row[i]; if (val[0] != 0) { AllocVar(cg); cg->chrom = pos->chrom; cg->chromStart = pos->pos; cg->val = cppNeedDouble(cpp, row, i); cg->marker = cloneString(marker); slAddHead(&fileEl->cgList, cg); } } } freeMem(marker); } if (report) printf("Mapped %d of %d (%3.1f%%) of markers<BR>\n", match, total, 100.0*match/total); }
void LDAModel::train() { if (descriptor_matrix_.cols() == 0) { throw Exception::InconsistentUsage(__FILE__, __LINE__, "Data must be read into the model before training!"); } readLabels(); // map values of Y to their index map<int, unsigned int> label_to_pos; for (unsigned int i = 0; i < labels_.size(); i++) { label_to_pos.insert(make_pair(labels_[i], i)); } // calculate sigma_ = covariance matrix of descriptors sigma_.resize(descriptor_matrix_.cols(), descriptor_matrix_.cols()); for (int i = 0; i < descriptor_matrix_.cols(); i++) { double mi = Statistics::getMean(descriptor_matrix_, i); for (int j = 0; j < descriptor_matrix_.cols(); j++) { sigma_(i, j) = Statistics::getCovariance(descriptor_matrix_, i, j, mi); } } Eigen::MatrixXd I(sigma_.cols(), sigma_.cols()); I.setIdentity(); I *= lambda_; sigma_ += I; sigma_ = sigma_.inverse(); mean_vectors_.resize(Y_.cols()); no_substances_.clear(); no_substances_.resize(labels_.size(), 0); for (int c = 0; c < Y_.cols(); c++) { vector < int > no_substances_c(labels_.size(), 0); // no of substances in each class for activitiy c mean_vectors_[c].resize(labels_.size(), descriptor_matrix_.cols()); mean_vectors_[c].setZero(); for (int i = 0; i < descriptor_matrix_.rows(); i++) // calculate sum vector of each class { int yi = static_cast < int > (Y_(i, c)); // Y_ will contains only ints for classifications int pos = label_to_pos.find(yi)->second; for (int j = 0; j < descriptor_matrix_.cols(); j++) { mean_vectors_[c](pos, j) += descriptor_matrix_(i, j); } if (c == 0) no_substances_c[pos]++; } for (int i = 0; i < mean_vectors_[c].rows(); i++) // calculate mean vector of each class { if (no_substances_c[i] == 0) { mean_vectors_[c].row(i).setConstant(std::numeric_limits<double>::infinity()); // set mean of classes NOT occurring for activitiy c to inf } for (int j = 0; j < descriptor_matrix_.cols(); j++) { mean_vectors_[c](i, j) = mean_vectors_[c](i, j)/no_substances_c[i]; } } for (unsigned int i = 0; i < no_substances_.size(); i++) // update overall number of substances per class { no_substances_[i] += no_substances_c[i]; } } }
int main(int argc, char** argv) { ///////////////////////////////////////////////////// ///usage: ///AnormalyDetection -t [0 1] [ [-f] or [-d [0 1 2 3...] [-l lable] location] ] //AnormalyDetection -t [0 1] -f //AnormalyDetection -t [0 1] -d [0 1 2 3...] [-l lable] location /////////////////////////////////////////////////////// /*printf("argc = %d\n", argc); for(int i = 1; i < argc; i ++) printf("%d %s\n", i, argv[i]);*/ char **output = new char*[4]; for(int i = 0; i < 4; i ++) { output[i] = new char[MaxStringLength]; memcpy(output[i], "\0", MaxStringLength); } int n = 0; if(!options(argc, argv, output, n)) { printf("error usage!\n"); printf("usage:program options location\n"); printf("options:-t, -f, -d , -l\n"); return 1; } /*for(int i = 0; i < 4; i ++) { printf("%d: %s\n", i+1, output[i]); }*/ int type = atoi(output[0]); if(n == 1) { if(type == 0) { trainSVMModel(); } if(type == 1) { //printf("entering detection...\n"); predictSVM(); } return 0; } int dataset = atoi(output[1]); switch(dataset) { case 1://UMN frameWidth = 320; frameHeight = 240; break; case 2://BEHAVE frameWidth = 640; frameHeight = 480; break; case 3://UCSD_PED1 frameWidth = 238; frameHeight = 158; break; case 4://UCSD_PED2 frameWidth = 238; frameHeight = 158; break; default: break; } char* location = output[2]; vector<string> files; readDataset(location, files); if(type == 0) { trainSVMModel(files); } if(type == 1) { //printf("entering detection...\n"); vector<int> labels; readLabels(output[3], labels); predictSVM(files, labels); } return 0; }