void SourceTASReader::OnAfterFrames() { if (currentTick <= currentScript.GetScriptLength()) ++currentTick; if (conditions.empty() || iterationFinished) return; bool allTrue = true; for (auto& pointer : conditions) { allTrue = allTrue && pointer->IsTrue(currentTick, currentScript.GetScriptLength()); if (pointer->ShouldTerminate(currentTick, currentScript.GetScriptLength())) { iterationFinished = true; SearchResult(SearchResult::Fail); return; } } if (allTrue) { iterationFinished = true; SearchResult(SearchResult::Success); } }
void AnalyzeImageDlg::InitConnections() { connect(ui.btnBrowseSavePath, SIGNAL(clicked()), this, SLOT(OnBtnBrowseSavePathClicked())); connect(ui.btnRecovery, SIGNAL(clicked()), this, SLOT(OnBtnRecoveryClicked())); connect(ui.edtSearchStr, SIGNAL(textChanged(const QString&)), this, SLOT(OnEdtSearchStrTextChanged(const QString&))); connect(ui.btnSearch, SIGNAL(clicked()), this, SLOT(OnBtnSearchClicked())); connect(ui.btnExport, SIGNAL(clicked()), this, SLOT(OnBtnExportClicked())); connect(m_searchThd, SIGNAL(finished()), this, SLOT(SearchFinished())); connect(m_searchThd, SIGNAL(CurrentProgress(int)), this, SLOT(CurrentProgress(int))); connect(m_searchThd, SIGNAL(TotalProgress(int)), this, SLOT(TotalProgress(int))); connect(m_searchThd, SIGNAL(SearchResult(QString, __int64)), this, SLOT(SearchResult(QString, __int64))); connect(ui.btnBrowseImage, SIGNAL(clicked()), this, SLOT(OnBtnBrowseImageClicked())); }
void Search::search(const std::string query, const completion_t completion){ //find the query match std::string q(query); std::transform(q.begin(), q.end(), q.begin(), ::tolower); const long kSearchBeganTime=currentTimeMilliseconds(); if (q.empty()) { if (completion) completion(query, std::make_shared<results_t>(), currentTimeMilliseconds()-kSearchBeganTime); return; } FutureHolder *futureHolder(new FutureHolder()); futureHolder->future = std::async(std::launch::async, [=] () { p_results_t results(std::make_shared<results_t>()); std::string key(q); if (key.size()>3) key=key.substr(0,3); auto it(_index.find(key)); if (it!=_index.end()) { key=(*it).first; long long index((*it).second); auto lines(linesForCharIndex(index, key, q)); for (auto & line : lines) { //adding a result size_t loc(line.find(",")); if (loc != line.npos) { std::string word(line.substr(0,loc)); std::string data(line.substr(loc+1)); std::stringstream ss(data); std::vector<int> values; int i; while (ss >> i) { values.push_back(i); if (ss.peek() == ',') ss.ignore(); } for (int i (0); i<values.size(); i=i+2) results->push_back(SearchResult(word, values[i], values.at(i+1), currentTimeMilliseconds()-kSearchBeganTime)); }else{ //malformed string exception! } }
void SoundCloudSearchPlugin::onRequestFinished() { if (m_request->status() == QSoundCloud::ResourcesRequest::Ready) { SearchResultList results; const QVariantMap result = m_request->result().toMap(); const QVariantList list = result.value("collection").toList(); foreach (const QVariant &v, list) { const QVariantMap item = v.toMap(); const QString title = item.value("title").toString(); const QString url = item.value("permalink_url").toString(); const QString thumbnailUrl = item.value("artwork_url").toString(); const QString date = QDateTime::fromString(item.value("created_at").toString(), "yyyy/MM/dd HH:mm:ss +0000").toString("dd MMM yyyy"); const int secs = item.value("duration", 1000).toInt() / 1000; const QString duration = (secs > 0 ? QString("%1:%2").arg(secs / 60, 2, 10, QChar('0')) .arg(secs % 60, 2, 10, QChar('0')) : QString("--:--")); const QString description = item.value("description").toString(); const QString html = HTML.arg(url).arg(thumbnailUrl.section("-", 0, -2)).arg(date).arg(duration) .arg(description); results << SearchResult(title, html, url); } const QString next = result.value("next_href").toString(); if (!next.isEmpty()) { QVariantMap params; params["path"] = next.mid(next.lastIndexOf("/")); emit searchCompleted(results, params); } else { emit searchCompleted(results); } }
void PhotonKDTree::_knnOnPhtonKDTree(const Eigen::Vector3f & position, int N, PhotonKDTree::search_queue & candidates, int startIdx, int lastIdx, int axis) { if (startIdx <= lastIdx) { auto currIdx = middleIdx(Range(startIdx, lastIdx + 1)); auto photonPos = photons[currIdx].position; Eigen::Vector3f dp = photonPos - position; float sqrdist = dp.dot(dp); candidates.push(SearchResult(currIdx, sqrdist)); if (candidates.size() > N) { candidates.pop(); } auto searchLeft = [&](){ auto newRange = lowerRange(Range(startIdx, lastIdx + 1)); this->_knnOnPhtonKDTree(position, N, candidates, newRange.begin, newRange.end - 1, nextAxis(axis)); }; auto searchRight = [&](){ auto newRange = upperRange(Range(startIdx, lastIdx + 1)); this->_knnOnPhtonKDTree(position, N, candidates, newRange.begin, newRange.end - 1, nextAxis(axis)); }; bool searchedLeft = true; if (sparseless(axis)(position, photonPos)) { searchLeft(); } else { searchRight(); searchedLeft = false; } /// If the candidate hypersphere crosses the splitting plane, then /// look "on the other side of the plane by examining the other subtree" float farthestDist = candidates.top().squareDistance; float diff = photonPos(axis) - position(axis); if (candidates.size() < N || diff * diff < farthestDist) { if (searchedLeft) { searchRight(); } else { searchLeft(); } } } }
SearchResult ParseSearchResult( not_null<PeerData*> peer, Storage::SharedMediaType type, MsgId messageId, SparseIdsLoadDirection direction, const MTPmessages_Messages &data) { auto result = SearchResult(); result.noSkipRange = MsgRange{ messageId, messageId }; auto messages = [&] { switch (data.type()) { case mtpc_messages_messages: { auto &d = data.c_messages_messages(); App::feedUsers(d.vusers); App::feedChats(d.vchats); result.fullCount = d.vmessages.v.size(); return &d.vmessages.v; } break; case mtpc_messages_messagesSlice: { auto &d = data.c_messages_messagesSlice(); App::feedUsers(d.vusers); App::feedChats(d.vchats); result.fullCount = d.vcount.v; return &d.vmessages.v; } break; case mtpc_messages_channelMessages: { auto &d = data.c_messages_channelMessages(); if (auto channel = peer->asChannel()) { channel->ptsReceived(d.vpts.v); } else { LOG(("API Error: received messages.channelMessages when " "no channel was passed! (ParseSearchResult)")); } App::feedUsers(d.vusers); App::feedChats(d.vchats); result.fullCount = d.vcount.v; return &d.vmessages.v; } break; case mtpc_messages_messagesNotModified: { LOG(("API Error: received messages.messagesNotModified! " "(ParseSearchResult)")); return (const QVector<MTPMessage>*)nullptr; } break; } Unexpected("messages.Messages type in ParseSearchResult()"); }(); if (!messages) { return result; } auto addType = NewMessageExisting; result.messageIds.reserve(messages->size()); for (auto &message : *messages) { if (auto item = App::histories().addNewMessage(message, addType)) { auto itemId = item->id; if ((type == Storage::SharedMediaType::kCount) || item->sharedMediaTypes().test(type)) { result.messageIds.push_back(itemId); } accumulate_min(result.noSkipRange.from, itemId); accumulate_max(result.noSkipRange.till, itemId); } } if (messageId && result.messageIds.empty()) { result.noSkipRange = [&]() -> MsgRange { switch (direction) { case SparseIdsLoadDirection::Before: // All old loaded. return { 0, result.noSkipRange.till }; case SparseIdsLoadDirection::Around: // All loaded. return { 0, ServerMaxMsgId }; case SparseIdsLoadDirection::After: // All new loaded. return { result.noSkipRange.from, ServerMaxMsgId }; } Unexpected("Direction in ParseSearchResult"); }(); } return result; }
// Internal function for searching in the database. // For projects in C++ which use this project it might be preferable to use this function // to skip the wrapper. // Returns: number of results, -1 if maxResults != -1 and not all results were found int CDriveIndex::Find(wstring *strQuery, wstring *strQueryPath, vector<SearchResultFile> *rgsrfResults, BOOL bSort, BOOL bEnhancedSearch, int maxResults) { //These variables are used to control the flow of execution in this function. //Indicates where results should be searched unsigned int SearchWhere = IN_FILES; //Offset for vector marked by SearchWhere unsigned int iOffset = 0; //Used to skip the search when the previous two properties should be carried over to the next search without actually using them now. BOOL bSkipSearch = false; //Number of results in this search. -1 if more than maximum number of results. int nResults = 0; //No query, just ignore this call if(strQuery->length() == 0) { // Store this query LastResult.Query = wstring(TEXT("")); LastResult.Results = vector<SearchResultFile>(); return nResults; } if(strQueryPath != NULL) { //Check if the path actually matches the drive of this index WCHAR szDrive[_MAX_DRIVE]; _wsplitpath(strQueryPath->c_str(), szDrive, NULL, NULL, NULL); for(unsigned int j = 0; j != _MAX_DRIVE; j++) szDrive[j] = toupper(szDrive[j]); if(wstring(szDrive).compare(wstring(1,toupper(m_cDrive))) == 0) return 0; } //Create lower query string for case-insensitive search wstring strQueryLower(*strQuery); for(unsigned int j = 0; j != strQueryLower.length(); j++) strQueryLower[j] = tolower(strQueryLower[j]); const WCHAR *szQueryLower = strQueryLower.c_str(); //Create lower query path string for case-insensitive search wstring strQueryPathLower(strQueryPath != NULL ? *strQueryPath : TEXT("")); for(unsigned int j = 0; j != strQueryPathLower.length(); j++) strQueryPathLower[j] = tolower((*strQueryPath)[j]); wstring* pstrQueryPathLower = strQueryPath != NULL && strQueryPathLower.length() > 0 ? &strQueryPathLower : NULL; //If the query path is different from the last query so that the results are not valid anymore, the last query needs to be dropped if(!(strQueryPath != NULL && (LastResult.maxResults == -1 || LastResult.iOffset == 0) && (LastResult.SearchPath.length() == 0 || strQueryPathLower.find(LastResult.SearchPath) == 0))) LastResult = SearchResult(); //Calculate Filter value and length of the current query which are compared with the cached ones to skip many of them DWORDLONG QueryFilter = MakeFilter(&strQueryLower); DWORDLONG QueryLength = (QueryFilter & 0xE000000000000000ui64) >> 61ui64; //Bits 61-63 for storing lengths up to 8 QueryFilter = QueryFilter & 0x1FFFFFFFFFFFFFFFui64; //All but the last 3 bits //If the same query string as in the last query was used if(strQueryLower.compare(LastResult.Query) == 0 && LastResult.Results.size() > 0 && (LastResult.SearchEndedWhere == NO_WHERE && iOffset != 1)) // need proper condition here to skip { //Keep the position of the last result SearchWhere = LastResult.SearchEndedWhere; iOffset = LastResult.iOffset; bSkipSearch = true; for(int i = 0; i != LastResult.Results.size(); i++) { BOOL bFound = true; if(pstrQueryPathLower != NULL) { wstring strPathLower(LastResult.Results[i].Path); for(unsigned int j = 0; j != strPathLower.length(); j++) strPathLower[j] = tolower(LastResult.Results[i].Path[j]); bFound = strPathLower.find(strQueryPathLower) != -1; } if(bFound) { nResults++; //If the result limit has decreased and we have found all (shouldn't happen in common scenarios) if(maxResults != -1 && nResults > maxResults) { nResults = -1; //If we get here, the next incremental should start fresh, but only if it requires more results than this one. //To accomplish this we make this result contain no information about the origin of these results. SearchWhere = NO_WHERE; iOffset = 1; break; } rgsrfResults->insert(rgsrfResults->end(), LastResult.Results[i]); } } //if the last search was limited and didn't finish because it found enough files and we don't have the maximum number of results yet //we need to continue the search where the last one stopped. if(LastResult.maxResults != -1 && LastResult.SearchEndedWhere != NO_WHERE && (maxResults == -1 || nResults < maxResults)) bSkipSearch = false; } //If this query is more specific than the previous one, it can use the results from the previous query else if(strQueryLower.find(LastResult.Query) != -1 && LastResult.Results.size() > 0) { bSkipSearch = true; //Keep the position of the last result SearchWhere = LastResult.SearchEndedWhere; iOffset = LastResult.iOffset; FindInPreviousResults(*strQuery, szQueryLower, QueryFilter, QueryLength, pstrQueryPathLower, *rgsrfResults, 0, bEnhancedSearch, maxResults, nResults); //if the last search was limited and didn't finish because it found enough files and we don't have the maximum number of results yet //we need to continue the search where the last one stopped. if(LastResult.maxResults != -1 && LastResult.SearchEndedWhere != NO_WHERE && (maxResults == -1 || nResults < maxResults)) bSkipSearch = false; } DWORDLONG FRNPath; long long nFilesInDir = -1; if(strQueryPath != NULL && strQueryPath->length()) { FRNPath = PathToFRN(strQueryPath); wstring strPath2; GetDir(FRNPath, &strPath2); int iOffset = (int) FindDirOffsetByIndex(FRNPath); if(iOffset != -1) nFilesInDir = rgDirectories[iOffset].nFiles; } if(SearchWhere == IN_FILES && iOffset == 0 && nFilesInDir != -1 && nFilesInDir < 10000 && !bSkipSearch) { FindRecursively(*strQuery, szQueryLower, QueryFilter, QueryLength, strQueryPath, *rgsrfResults, bEnhancedSearch, maxResults, nResults); SearchWhere = NO_WHERE; } else if(SearchWhere == IN_FILES && !bSkipSearch) { //Find in file index FindInJournal(*strQuery, szQueryLower, QueryFilter, QueryLength, (strQueryPath != NULL ? &strQueryPathLower : NULL), rgFiles, *rgsrfResults, iOffset, bEnhancedSearch, maxResults, nResults); //If we found the maximum number of results in the file index we stop here if(maxResults != -1 && nResults == -1) iOffset++; //Start with next entry on the next incremental search else //Search isn't limited or not all results found yet, continue in directory index { SearchWhere = IN_DIRECTORIES; iOffset = 0; } } if(SearchWhere == IN_DIRECTORIES && !bSkipSearch) { //Find in directory index FindInJournal(*strQuery, szQueryLower, QueryFilter, QueryLength, pstrQueryPathLower, rgDirectories, *rgsrfResults, iOffset, bEnhancedSearch, maxResults, nResults); //If we found the maximum number of results in the directory index we stop here if(maxResults != -1 && nResults == -1) iOffset++; //Start with next entry on the next incremental search else //Search isn't limited or less than the maximum number of results found { SearchWhere = NO_WHERE; iOffset = 0; } } //Sort by match quality and name if(bSort) sort(rgsrfResults->begin(), rgsrfResults->end()); // Store this query LastResult.Query = wstring(strQueryLower); // Store search path LastResult.SearchPath = strQueryPathLower; //Clear old results, they will be replaced with the current ones LastResult.Results = vector<SearchResultFile>(); //Store number of results (Needed for incremental search) LastResult.iOffset = iOffset; //Store if this search was limited LastResult.maxResults = maxResults; //Store where the current search ended due to file limit (or if it didn't); LastResult.SearchEndedWhere = SearchWhere; //Update last results for(unsigned int i = 0; i != rgsrfResults->size(); i++) LastResult.Results.insert(LastResult.Results.end(), (*rgsrfResults)[i]); return nResults; }
void CDriveIndex::ClearLastResult() { LastResult = SearchResult(); }
// Set "toReturn" when NEED_FETCH. PlanStage::StageState NearStage::bufferNext(WorkingSetID* toReturn, Status* error) { // // Try to retrieve the next covered member // if (!_nextInterval) { StatusWith<CoveredInterval*> intervalStatus = nextInterval(_txn, _workingSet, _collection); if (!intervalStatus.isOK()) { _searchState = SearchState_Finished; *error = intervalStatus.getStatus(); return PlanStage::FAILURE; } if (NULL == intervalStatus.getValue()) { _searchState = SearchState_Finished; return PlanStage::IS_EOF; } // CoveredInterval and its child stage are owned by _childrenIntervals _childrenIntervals.push_back(intervalStatus.getValue()); _nextInterval = _childrenIntervals.back(); _nextIntervalStats.reset(new IntervalStats()); _nextIntervalStats->minDistanceAllowed = _nextInterval->minDistance; _nextIntervalStats->maxDistanceAllowed = _nextInterval->maxDistance; _nextIntervalStats->inclusiveMaxDistanceAllowed = _nextInterval->inclusiveMax; } WorkingSetID nextMemberID; PlanStage::StageState intervalState = _nextInterval->covering->work(&nextMemberID); if (PlanStage::IS_EOF == intervalState) { _nextInterval = NULL; _nextIntervalSeen.clear(); _searchState = SearchState_Advancing; return PlanStage::NEED_TIME; } else if (PlanStage::FAILURE == intervalState) { *error = WorkingSetCommon::getMemberStatus(*_workingSet->get(nextMemberID)); return intervalState; } else if (PlanStage::NEED_FETCH == intervalState) { *toReturn = nextMemberID; return intervalState; } else if (PlanStage::ADVANCED != intervalState) { return intervalState; } // // Try to buffer the next covered member // WorkingSetMember* nextMember = _workingSet->get(nextMemberID); // The child stage may not dedup so we must dedup them ourselves. if (_nextInterval->dedupCovering && nextMember->hasLoc()) { if (_nextIntervalSeen.end() != _nextIntervalSeen.find(nextMember->loc)) return PlanStage::NEED_TIME; } ++_nextIntervalStats->numResultsFound; StatusWith<double> distanceStatus = computeDistance(nextMember); // Store the member's RecordId, if available, for quick invalidation if (nextMember->hasLoc()) { _nextIntervalSeen.insert(make_pair(nextMember->loc, nextMemberID)); } if (!distanceStatus.isOK()) { _searchState = SearchState_Finished; *error = distanceStatus.getStatus(); return PlanStage::FAILURE; } // If the member's distance is in the current distance interval, add it to our buffered // results. double memberDistance = distanceStatus.getValue(); bool inInterval = memberDistance >= _nextInterval->minDistance && (_nextInterval->inclusiveMax ? memberDistance <= _nextInterval->maxDistance : memberDistance < _nextInterval->maxDistance); // Update found distance stats if (_nextIntervalStats->minDistanceFound < 0 || memberDistance < _nextIntervalStats->minDistanceFound) { _nextIntervalStats->minDistanceFound = memberDistance; } if (_nextIntervalStats->maxDistanceFound < 0 || memberDistance > _nextIntervalStats->maxDistanceFound) { _nextIntervalStats->maxDistanceFound = memberDistance; } if (inInterval) { _resultBuffer.push(SearchResult(nextMemberID, memberDistance)); ++_nextIntervalStats->numResultsBuffered; // Update buffered distance stats if (_nextIntervalStats->minDistanceBuffered < 0 || memberDistance < _nextIntervalStats->minDistanceBuffered) { _nextIntervalStats->minDistanceBuffered = memberDistance; } if (_nextIntervalStats->maxDistanceBuffered < 0 || memberDistance > _nextIntervalStats->maxDistanceBuffered) { _nextIntervalStats->maxDistanceBuffered = memberDistance; } } else { // We won't pass this WSM up, so deallocate it _workingSet->free(nextMemberID); } return PlanStage::NEED_TIME; }
void SearchResultsDatabase::add(const EntityID &id) { shared_ptr<SearchResult> result(OS_NEW SearchResult(id)); m_objects.push_back(result); }
SearchResult findModule(const std::string& name, BoxedString* full_name, BoxedList* path_list) { static BoxedString* meta_path_str = internStringImmortal("meta_path"); BoxedList* meta_path = static_cast<BoxedList*>(sys_module->getattr(meta_path_str)); if (!meta_path || meta_path->cls != list_cls) raiseExcHelper(RuntimeError, "sys.meta_path must be a list of import hooks"); static BoxedString* findmodule_str = internStringImmortal("find_module"); for (int i = 0; i < meta_path->size; i++) { Box* finder = meta_path->elts->elts[i]; auto path_pass = path_list ? path_list : None; CallattrFlags callattr_flags{.cls_only = false, .null_on_nonexistent = false, .argspec = ArgPassSpec(2) }; Box* loader = callattr(finder, findmodule_str, callattr_flags, full_name, path_pass, NULL, NULL, NULL); if (loader != None) return SearchResult(loader); } if (!path_list) path_list = getSysPath(); if (path_list == NULL || path_list->cls != list_cls) { raiseExcHelper(RuntimeError, "sys.path must be a list of directory names"); } static BoxedString* path_hooks_str = internStringImmortal("path_hooks"); BoxedList* path_hooks = static_cast<BoxedList*>(sys_module->getattr(path_hooks_str)); if (!path_hooks || path_hooks->cls != list_cls) raiseExcHelper(RuntimeError, "sys.path_hooks must be a list of import hooks"); static BoxedString* path_importer_cache_str = internStringImmortal("path_importer_cache"); BoxedDict* path_importer_cache = static_cast<BoxedDict*>(sys_module->getattr(path_importer_cache_str)); if (!path_importer_cache || path_importer_cache->cls != dict_cls) raiseExcHelper(RuntimeError, "sys.path_importer_cache must be a dict"); llvm::SmallString<128> joined_path; for (int i = 0; i < path_list->size; i++) { Box* _p = path_list->elts->elts[i]; if (_p->cls != str_cls) continue; BoxedString* p = static_cast<BoxedString*>(_p); joined_path.clear(); llvm::sys::path::append(joined_path, p->s(), name); std::string dn(joined_path.str()); llvm::sys::path::append(joined_path, "__init__.py"); std::string fn(joined_path.str()); PyObject* importer = get_path_importer(path_importer_cache, path_hooks, _p); if (importer == NULL) throwCAPIException(); if (importer != None) { CallattrFlags callattr_flags{.cls_only = false, .null_on_nonexistent = false, .argspec = ArgPassSpec(1) }; Box* loader = callattr(importer, findmodule_str, callattr_flags, full_name, NULL, NULL, NULL, NULL); if (loader != None) return SearchResult(loader); } if (pathExists(fn)) return SearchResult(std::move(dn), SearchResult::PKG_DIRECTORY); joined_path.clear(); llvm::sys::path::append(joined_path, std::string(p->s()), name + ".py"); fn = joined_path.str(); if (pathExists(fn)) return SearchResult(std::move(fn), SearchResult::PY_SOURCE); joined_path.clear(); llvm::sys::path::append(joined_path, p->s(), name + ".pyston.so"); fn = joined_path.str(); if (pathExists(fn)) return SearchResult(std::move(fn), SearchResult::C_EXTENSION); } return SearchResult("", SearchResult::SEARCH_ERROR); } PyObject* PyImport_GetImporter(PyObject* path) noexcept { PyObject* importer = NULL, * path_importer_cache = NULL, * path_hooks = NULL; if ((path_importer_cache = PySys_GetObject("path_importer_cache"))) { if ((path_hooks = PySys_GetObject("path_hooks"))) { importer = get_path_importer(path_importer_cache, path_hooks, path); } } Py_XINCREF(importer); /* get_path_importer returns a borrowed reference */ return importer; }
/** * @brief Processed a search request. * @param request the request to proceed. */ u_int32_t ORBSearcher::searchImage(SearchRequest &request) { timeval t[5]; gettimeofday(&t[0], NULL); cout << "Loading the image and extracting the ORBs." << endl; Mat img; u_int32_t i_ret = ImageLoader::loadImage(request.imageData.size(), request.imageData.data(), img); if (i_ret != OK) return i_ret; vector<KeyPoint> keypoints; Mat descriptors; ORB(1000, 1.02, 100)(img, noArray(), keypoints, descriptors); gettimeofday(&t[1], NULL); cout << "time: " << getTimeDiff(t[0], t[1]) << " ms." << endl; cout << "Looking for the visual words. " << endl; unordered_map<u_int32_t, list<Hit> > imageReqHits; // key: visual word, value: the found angles for (unsigned i = 0; i < keypoints.size(); ++i) { #define NB_NEIGHBORS 1 vector<int> indices(NB_NEIGHBORS); vector<int> dists(NB_NEIGHBORS); wordIndex->knnSearch(descriptors.row(i), indices, dists, NB_NEIGHBORS); for (unsigned j = 0; j < indices.size(); ++j) { const unsigned i_wordId = indices[j]; if (imageReqHits.find(i_wordId) == imageReqHits.end()) { // Convert the angle to a 16 bit integer. Hit hit; hit.i_imageId = 0; hit.i_angle = keypoints[i].angle / 360 * (1 << 16); hit.x = keypoints[i].pt.x; hit.y = keypoints[i].pt.y; imageReqHits[i_wordId].push_back(hit); } } } cout << imageReqHits.size() << " visual words kept for the request." << endl; const unsigned i_nbTotalIndexedImages = index->getTotalNbIndexedImages(); cout << i_nbTotalIndexedImages << " images indexed in the index." << endl; unordered_map<u_int32_t, vector<Hit> > indexHits; // key: visual word id, values: index hits. index->getImagesWithVisualWords(imageReqHits, indexHits); gettimeofday(&t[2], NULL); cout << "time: " << getTimeDiff(t[1], t[2]) << " ms." << endl; cout << "Ranking the images." << endl; unordered_map<u_int32_t, float> weights; // key: image id, value: image score. for (unordered_map<u_int32_t, vector<Hit> >::const_iterator it = indexHits.begin(); it != indexHits.end(); ++it) { const vector<Hit> &hits = it->second; const float f_weight = log((float)i_nbTotalIndexedImages / hits.size()); for (vector<Hit>::const_iterator it2 = hits.begin(); it2 != hits.end(); ++it2) { /* TF-IDF according to the paper "Video Google: * A Text Retrieval Approach to Object Matching in Videos" */ unsigned i_totalNbWords = index->countTotalNbWord(it2->i_imageId); weights[it2->i_imageId] += f_weight / i_totalNbWords; } } priority_queue<SearchResult> rankedResults; for (tr1::unordered_map<unsigned, float>::const_iterator it = weights.begin(); it != weights.end(); ++it) rankedResults.push(SearchResult(it->second, it->first)); gettimeofday(&t[3], NULL); cout << "time: " << getTimeDiff(t[2], t[3]) << " ms." << endl; cout << "Reranking 300 among " << rankedResults.size() << " images." << endl; priority_queue<SearchResult> rerankedResults; reranker.rerank(imageReqHits, indexHits, rankedResults, rerankedResults, 300); gettimeofday(&t[4], NULL); cout << "time: " << getTimeDiff(t[3], t[4]) << " ms." << endl; cout << "Returning the results. " << endl; returnResults(rerankedResults, request, 100); #if 0 // Draw keypoints and ellipses. Mat img_res; drawKeypoints(img, cleanKeypoints, img_res, Scalar::all(-1), DrawMatchesFlags::DEFAULT); for (unsigned i = 0; i < ellipses.size(); ++i) ellipse( img_res, ellipses[i], Scalar(0, 0, 255), 1); // Show the image. imshow("Keypoints 1", img_res); #endif return SEARCH_RESULTS; }
void SearchImageThread::run() { HANDLE hFile = CreateFile( m_imageFile.c_str(), FILE_GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL); if ( INVALID_HANDLE_VALUE == hFile ) { return; } LARGE_INTEGER fs = {0}; GetFileSizeEx(hFile, &fs); LONGLONG fileSize = fs.QuadPart; DWORD readPieceSize = BufferSize; LONGLONG currentProcess = 0; DWORD readed = 0; emit TotalProgress(100); unsigned char* buffer = new unsigned char[readPieceSize]; QByteArray searchStr = m_utf8 ? m_searchStr.toUtf8() : m_searchStr.toLocal8Bit(); int patternLen = searchStr.length(); unsigned char* pattern = new unsigned char[patternLen]; memcpy(pattern, searchStr.data(), patternLen); while (true) { memset(buffer, 0, readPieceSize); ReadFile(hFile, buffer, readPieceSize, &readed, NULL); // Search buffer char displayText[ContentSize+1] = {0}; for ( int i = 0; i < readPieceSize; ) { if ( 0 == memcmp(buffer+i, pattern, patternLen) ) { for ( int j = 0; j < ContentSize; ++j ) { if ( buffer[i+j] == 0 ) displayText[j] = ' '; else displayText[j] = buffer[i+j]; } QString result = m_utf8 ? QString::fromUtf8(displayText, ContentSize+1) : QString::fromLocal8Bit(displayText, ContentSize+1); emit SearchResult(result, currentProcess + i); i += ContentSize; } else ++i; } currentProcess += readed; emit CurrentProgress((int)(currentProcess * 100 / fileSize)); if ( 0 == readed ) break; } delete [] buffer; CloseHandle(hFile); }