void PlaceDatabase::getFrame(int64_t id, frame_common::Frame& frame) const { checkErr(sqlite3_bind_int64(select_frame_stmt_, 1, id), "Couldn't bind row id"); checkErr(sqlite3_step(select_frame_stmt_), "SELECT frame didn't return data", SQLITE_ROW); // Extract camera parameters frame_common::CamParams cam; cam.fx = sqlite3_column_double(select_frame_stmt_, 0); cam.fy = sqlite3_column_double(select_frame_stmt_, 1); cam.cx = sqlite3_column_double(select_frame_stmt_, 2); cam.cy = sqlite3_column_double(select_frame_stmt_, 3); cam.tx = sqlite3_column_double(select_frame_stmt_, 4); frame.setCamParams(cam); // Extract disparities and "good points" index int num_keypoints = sqlite3_column_int(select_frame_stmt_, 7); extractVector(select_frame_stmt_, 5, frame.disps, num_keypoints); extractVector(select_frame_stmt_, 6, frame.goodPts, num_keypoints); // Extract keypoints and descriptors extractVector(select_frame_stmt_, 8, frame.kpts, num_keypoints); int descriptor_length = sqlite3_column_int(select_frame_stmt_, 9); assert(descriptor_length > 0); const void* desc_data = sqlite3_column_blob(select_frame_stmt_, 10); int desc_bytes = sqlite3_column_bytes(select_frame_stmt_, 10); int step = desc_bytes / num_keypoints; assert(step >= descriptor_length * (int)sizeof(float)); const cv::Mat tmp(num_keypoints, descriptor_length, cv::DataType<float>::type, const_cast<void*>(desc_data), step); tmp.copyTo(frame.dtors); // Finally, reconstruct frame.pts from keypoints and disparities frame.pts.resize(num_keypoints); for (int i = 0; i < num_keypoints; ++i) { if (frame.goodPts[i]) { Eigen::Vector3d pt(frame.kpts[i].pt.x, frame.kpts[i].pt.y, frame.disps[i]); frame.pts[i].head<3>() = frame.pix2cam(pt); frame.pts[i](3) = 1.0; } } checkErr(sqlite3_step(select_frame_stmt_), "SELECT frame returned more than one row", SQLITE_DONE); checkErr(sqlite3_reset(select_frame_stmt_), "Couldn't reset SELECT frame statement"); }
void KstBindCurve::setYMinusErrorVector(KJS::ExecState *exec, const KJS::Value& value) { KstVCurvePtr d = makeCurve(_d); if (d) { KstVectorPtr vp = extractVector(exec, value); if (vp) { KstWriteLocker wl(d); d->setYMinusError(vp); } } }
void PlaceDatabase::extractImage(cv::Mat& image, int col) const { std::vector<uchar> buf; extractVector(select_images_stmt_, col, buf); if (buf.size() == 0) image = cv::Mat(); else { cv::Mat mat(1, buf.size(), CV_8UC1, &buf[0]); image = cv::imdecode(mat, CV_LOAD_IMAGE_ANYCOLOR); } }
// Extracts vector recursively Rpn::Vector Parser::extractVector() { if (m_lexer->lexeme().type != LexemeOpeningSquareBracket) { THROW(EExpected(tr("Opening bracket for vector initialization"))); } m_lexer->nextLexeme(); Rpn::Vector result; // Multi-dimensional vector. Recursive calls if (m_lexer->lexeme().type == LexemeOpeningSquareBracket) { m_lexer->previousLexeme(); QList<Rpn::Vector> elements; do { m_lexer->nextLexeme(); elements << extractVector(); } while (m_lexer->lexeme().type == LexemeComma); result = m_codeGenerator->generateVector(elements); } // One-dimensional vector else { m_lexer->previousLexeme(); QList<Number> elements; do { m_lexer->nextLexeme(); Rpn::CodeThread elementThread = expression(); Rpn::Operand operand = m_calculator->calculate(elementThread); if (operand.type != Rpn::OperandNumber) { THROW(EIncorrectVectorInitialization()); } elements << operand.value.value<Number>(); } while (m_lexer->lexeme().type == LexemeComma); result = m_codeGenerator->generateVector(elements); } if (m_lexer->lexeme().type != LexemeClosingSquareBracket) { THROW(EExpected(tr("Closing bracket for vector initialization"))); } m_lexer->nextLexeme(); return result; }
void PlaceDatabase::loadDocumentDatabase(const std::string& weights_file) { document_db_.loadWeights(weights_file); // Repopulate documents static const char SELECT_DOC_SQL[] = "SELECT id, document FROM places"; sqlite3_stmt *stmt = NULL; checkErr(sqlite3_prepare_v2(persistent_db_, SELECT_DOC_SQL, sizeof(SELECT_DOC_SQL), &stmt, NULL), "Couldn't prepare SELECT documents statement"); vt::Document words; int err; int64_t id = 0; while ((err = sqlite3_step(stmt)) == SQLITE_ROW) { id = sqlite3_column_int(stmt, 0); extractVector(stmt, 1, words); vt::DocId doc_id = document_db_.insert(words); doc_to_place_id_[doc_id] = id; } printf("Last loaded document id = %d\n", (int)id); checkErr(err, "Error executing spatial query", SQLITE_DONE); checkErr(sqlite3_finalize(stmt), "Couldn't finalize SELECT documents statement"); }
KJS::Object KstBindCurve::construct(KJS::ExecState *exec, const KJS::List& args) { KstVectorPtr x, y, ex, ey, exm, eym; if (args.size() > 0) { x = extractVector(exec, args[0]); if (!x) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Object(); } } if (args.size() > 1) { y = extractVector(exec, args[1]); if (!y) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Object(); } } if (args.size() > 2) { ex = extractVector(exec, args[2]); if (!ex) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Object(); } } if (args.size() > 3) { ey = extractVector(exec, args[3]); if (!ey) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Object(); } } if (args.size() > 4) { exm = extractVector(exec, args[4]); if (!exm) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Object(); } } if (args.size() > 5) { eym = extractVector(exec, args[5]); if (!eym) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Object(); } } if (args.size() > 6) { KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError); exec->setException(eobj); return KJS::Object(); } if (!x || !y) { // force at least X and Y vectors KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError); exec->setException(eobj); return KJS::Object(); } QColor color = KstColorSequence::next(); KstVCurvePtr d = new KstVCurve(QString::null, x, y, ex, ey, exm, eym, color); KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(d.data()); KST::dataObjectList.lock().writeUnlock(); return KJS::Object(new KstBindCurve(exec, d)); }
// Vector = '[' Expression, { ',' Expression } ']' Rpn::CodeThread Parser::vector() { return m_codeGenerator->packVector(extractVector()); }
KJS::Object KstBindPowerSpectrum::construct(KJS::ExecState *exec, const KJS::List& args) { if (args.size() < 2) { KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError); exec->setException(eobj); return KJS::Object(); } if (args[1].type() != KJS::NumberType) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Object(); } double gaussianSigma = 0.0; double freq = args[1].toNumber(exec); bool average = true; unsigned len = 16; bool apodize = true; bool removeMean = true; int apodizeFxn = WindowOriginal; int output = PSDAmplitudeSpectralDensity; QString vunits = "V"; QString runits = "Hz"; KstVectorPtr v = extractVector(exec, args[0]); if (!v) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Object(); } if (args.size() > 2) { if (args[2].type() != KJS::BooleanType) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Object(); } average = args[2].toBoolean(exec); } if (args.size() > 3) { if (args[3].type() != KJS::NumberType || !args[3].toUInt32(len)) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Object(); } } if (args.size() > 4) { if (args[4].type() != KJS::BooleanType) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Object(); } apodize = args[4].toBoolean(exec); } if (args.size() > 5) { if (args[5].type() != KJS::BooleanType) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Object(); } removeMean = args[5].toBoolean(exec); } if (args.size() > 6) { if (args[6].type() != KJS::StringType) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Object(); } vunits = args[6].toString(exec).qstring(); } if (args.size() > 7) { if (args[7].type() != KJS::StringType) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Object(); } runits = args[7].toString(exec).qstring(); } if (args.size() > 8) { if (args[8].type() != KJS::NumberType) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Object(); } apodizeFxn = args[8].toInt32(exec); } if (args.size() > 9) { if (args[9].type() != KJS::NumberType) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Object(); } gaussianSigma = args[9].toNumber(exec); } if (args.size() > 10) { if (args[10].type() != KJS::NumberType) { KJS::Object eobj = KJS::Error::create(exec, KJS::TypeError); exec->setException(eobj); return KJS::Object(); } output = args[10].toInt32(exec); } if (args.size() > 11) { KJS::Object eobj = KJS::Error::create(exec, KJS::SyntaxError); exec->setException(eobj); return KJS::Object(); } KstPSDPtr d = new KstPSD(QString::null, v, freq, average, len, apodize, removeMean, vunits, runits, (ApodizeFunction)apodizeFxn, gaussianSigma, (PSDType)output); KST::dataObjectList.lock().writeLock(); KST::dataObjectList.append(d.data()); KST::dataObjectList.lock().unlock(); return KJS::Object(new KstBindPowerSpectrum(exec, d)); }