Quantcast
Channel: OpenCV Q&A Forum - RSS feed
Viewing all articles
Browse latest Browse all 41027

trying to search flann index getting weird errors

$
0
0
UPDATE: ok I got it working, but I don't understand the output. It seems to be repeating the same matches over and over, and I'm not sure why. I have updated the code. Here is some sample output 19:02:16.067 Debug VideoTwin: ../VideoTwin/mainwindow.cpp(325) - frame 16550 match at 10043 27 25 distance 4.45768e-310 19:02:16.067 Debug VideoTwin: ../VideoTwin/mainwindow.cpp(325) - frame 16550 match at 10043 27 25 distance 4.51518e-310 19:02:16.067 Debug VideoTwin: ../VideoTwin/mainwindow.cpp(325) - frame 16550 match at 10043 27 25 distance 4.56611e-310 19:02:16.067 Debug VideoTwin: ../VideoTwin/mainwindow.cpp(325) - frame 16550 match at 10043 25 27 distance 4.51943e-310 19:02:16.067 Debug VideoTwin: ../VideoTwin/mainwindow.cpp(325) - frame 16550 match at 10043 27 25 distance 4.54404e-310 19:02:16.067 Debug VideoTwin: ../VideoTwin/mainwindow.cpp(325) - frame 16550 match at 10043 27 28 distance 4.50648e-310 19:02:16.067 Debug VideoTwin: ../VideoTwin/mainwindow.cpp(325) - frame 16550 match at 10043 27 28 distance 4.53895e-310 19:02:16.067 Debug VideoTwin: ../VideoTwin/mainwindow.cpp(325) - frame 16550 match at 10043 27 25 distance 4.50118e-310 19:02:16.067 Debug VideoTwin: ../VideoTwin/mainwindow.cpp(325) - frame 16550 match at 10043 27 25 distance 4.50012e-310 19:02:16.067 Debug VideoTwin: ../VideoTwin/mainwindow.cpp(325) - frame 16550 match at 10043 27 25 distance 4.46744e-310 19:02:16.067 Debug VideoTwin: ../VideoTwin/mainwindow.cpp(325) - frame 16550 match at 10043 27 25 distance 4.59709e-310 19:02:16.067 Debug VideoTwin: ../VideoTwin/mainwindow.cpp(325) - frame 16550 match at 10043 27 25 distance 4.47041e-310 19:02:16.067 Debug VideoTwin: ../VideoTwin/mainwindow.cpp(325) - frame 16550 match at 10043 27 25 distance 4.51837e-310 Here I am saving the descriptors for each frame to a sqlite database UMat frame; vector< cv::KeyPoint > keypoints; Ptr odetector = cv::ORB::create(500); UMat imgDescriptor; VideoCapture videocap(video.toStdString()); if (!videocap.isOpened()) { failedstream << video << " could not be opened. Check permissions" << endl; return; } odetector->detect(frame,keypoints); odetector->compute(frame,keypoints,imgDescriptor); Mat imgDescriptorMat = imgDescriptor.getMat(cv::ACCESS_READ); FileStorage tempfs("temp.yml", FileStorage::WRITE | FileStorage::MEMORY | FileStorage::FORMAT_YAML); tempfs << "descriptors" << imgDescriptorMat; string ts = tempfs.releaseAndGetString(); frame_insert.bindValue(":descriptors", ts.c_str()); Here I am loading them back and building the index Mat indexTemp; flann::Index index; string buffer; while (true) { buffer = indexBuilder.value("descriptors").toString().toStdString(); Mat mat; Mat matonerow; FileStorage fs(buffer,FileStorage::READ | FileStorage::MEMORY | FileStorage::FORMAT_YAML); fs["descriptors"] >> mat; fs.release(); frm tmp; try { mat.copyTo(tmp.descriptors); } catch (Exception e) { qWarning() << "problem copyting mat to frm" << e.err.c_str() << e.msg.c_str(); } tmp.file = indexBuilder.value("file").toString(); tmp.position = indexBuilder.value("position").toInt(); frames.append(tmp); try { if (mat.rows < 500) mat.push_back(Mat::zeros((500 - mat.rows),32,CV_8U)); matonerow = mat.reshape(1,1); } catch (Exception e) { qDebug() << "problem creating zeros Mat"; } try { indexTemp.push_back(matonerow); } catch (Exception e) { qCritical() << "failed to copy row of Mat at loop" << iterations << e.err.c_str() << e.msg.c_str(); } progress->setValue(iterations); iterations++; if (!indexBuilder.next()) break; } try { index.build(indexTemp,cv::flann::LshIndexParams(20,10,2),cvflann::FLANN_DIST_HAMMING); } catch (Exception e) { qWarning() << "problem building index"; } and here I am trying to search the index for each frame Mat mat = frame.descriptors; Mat indices; Mat dists; try { index.knnSearch(desc,indices,dists,20); } catch (Exception e) { qWarning() << "index search failure" << e.err.c_str() << e.msg.c_str(); } for (int i = 0; i < indices.rows; i++ ) { qDebug() << "frame"<< frame.position << "match at" << frames.at( indices.at(i,0)).position << indices.at(i,1) << indices.at(i,2) << "distance" << dists.at(i,0); }

Viewing all articles
Browse latest Browse all 41027

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>