Ask Your Question

phirestalker's profile - activity

2016-02-27 18:18:10 -0600 asked a question does opencl require any other optional tags to work?

If I compiled the opencv3.1 library without opengl support, is opencl through the TAPI still able to use the GPU accelerated code? If I have an NVIDIA based card do I need cuda compiled in to see the benefits?

2016-02-05 23:58:39 -0600 received badge  Self-Learner (source)
2016-02-05 13:57:01 -0600 commented answer cv::flann::index::knnsearch values of indices and dists

thanks, edited

2016-02-05 13:12:26 -0600 answered a question cv::flann::index::knnsearch values of indices and dists

here is some code that will solve the question

bool goodMatch(int distance, float percent, int descriptornum)
{
    int descriptorbits = 256 * descriptornum;
    int result = descriptorbits - (descriptorbits * percent);
    return (distance <= result);
}

distance - the value returned in dists percent - float value of percent (i.e. 90% = 0.9) descriptornum - the number of descriptors

2016-02-03 20:03:44 -0600 answered a question Flann index for video duplicate finding

ok I figured it out this code should work when plugged with a qstringlist of files

QStringList videos;
Mat indexTemp;
struct frm
{
    QString file;
    int position;
    cv::Mat descriptors;
};
QList<frm> frames;

foreach (video, videos)
{
    process(video);
}

for (i = 0; i < indexTemp.rows; i++)
{
    Mat mat = indexTemp.row(i);
    Mat indices;
    Mat dists;
    int k = 3;
    if (!mat.isContinuous() || mat.empty())
        return;
    try
    {
        mat = mat.reshape(1,1);
        index.knnSearch(mat,indices,dists,k);
    }
    catch (Exception e)
    {
        qWarning() << "index search failure" << e.err.c_str() << e.msg.c_str();
    }
    catch (exception& e)
    {
        qWarning() << "index search failure" << e.what();
    }
    for (int j = 0; j < indices.cols; j++)
    {
        if (indices.at<int>(0,i) == -1 || dists.at<int>(0,j) < 12800) //knnsearch returns -1 for all cols after the matches it was able to find. 12800 is about 90% match with 500 ORB descriptors
            continue;
        try
        {
            QTime matchtime(0,0,0,0);
            int matchms = frames.at(i).position;
            matchtime = matchtime.addMSecs(matchms);
            int temp = dists.at<int>(0,j);
            qDebug() << frames.at(i).file << "frame"<<  timestamp.toString("hh:mm:ss") << "match at"<< frames.at(indices.at<int>(0,j)).file << matchtime.toString("hh:mm:ss") << "distance" << temp;
        }
        catch (Exception e)
        {
            qWarning() << "failure in indices" << e.err.c_str() << e.msg.c_str() << e.func.c_str();
        }
        catch (exception &e)
        {
            qWarning() << "failure in indices" << e.what();
        }
    }
}
index.build(indexTemp,cv::flann::LshIndexParams(12,20,3), cvflann::FLANN_DIST_HAMMING);


void process(Qstring video)
{
    if (video.isEmpty())
        return;
    int interval = 500;
    int current_interval = 0;
    UMat frame;
    vector< cv::KeyPoint > keypoints;
    Ptr<DescriptorExtractor> odetector = cv::ORB::create(500);
    UMat imgDescriptor;
    VideoCapture videocap(video.toStdString());
    if (!videocap.isOpened())
    {
        failedstream << video << " could not be opened. Check permissions" << endl;
        return;
    }
    for(; ; )
    {
        if (current_interval != 0)
            videocap.set(CV_CAP_PROP_POS_MSEC,current_interval);
        if (current_interval > videocap.get(CV_CAP_PROP_POS_MSEC) + 400) // I found some videos needed this in case the last from is not quite 500 ms away from the previous one
            break;
        if (!videocap.read(frame))
            break;
        current_interval += interval;
        if (frame.empty() || !frame.isContinuous()) //skipping bad frames
            continue;
        odetector->detect(frame,keypoints);
        odetector->compute(frame,keypoints,imgDescriptor);
        if (imgDescriptor.empty() || !imgDescriptor.isContinuous()) // don't ask me how but even with all the frame checking this is still needed
        {
            qDebug() << "descriptors empty or corrupted" << imgDescriptor.empty() << imgDescriptor.isContinuous();
            continue;
        }
        {
        Mat imgDescriptorMat = imgDescriptor.getMat(cv::ACCESS_RW);
        Mat matonerow;
        frm tmp;
        tmp.file = video;
        tmp.position = current_interval;
        if (imgDescriptorMat.rows < 500)
            imgDescriptorMat.push_back(Mat::zeros((500 - imgDescriptorMat.rows),32,CV_8U));
        matonerow = imgDescriptorMat.reshape(1,1);
        indexTemp.push_back(matonerow);
        imgDescriptorMat.copyTo(tmp.descriptors);
        frames.append(tmp);
    }
}
2016-02-03 00:29:10 -0600 commented question cv::flann::index::knnsearch values of indices and dists

it returns the amount of differing bits between the 2 matches. so for 500 descriptors at 32 BYTES each so 256 bits, 256 X 500 descriptors 128,000 bits per set of descriptors so a 90% match would mean a value of 12,800 so anything lower than that is a good match

2016-02-03 00:13:01 -0600 commented question cv::flann::index::knnsearch values of indices and dists

Thanks I did some reading and I think I've got a formula

2016-02-02 14:47:41 -0600 asked a question cv::flann::index::knnsearch values of indices and dists

ok given the following code

    index.knnSearch(mat,indices,dists,3);

when using binary descriptors how do I make dists results into a useful ratio or percentage match?

2016-02-02 13:12:32 -0600 commented question SIGSEGV in flann getNeighbors function

ok I made the index data global and now I get

Assertion failed: (queries.cols == veclen()), function knnSearch, file /tmp/opencv320160131-91598-1dax8xj/opencv-3.1.0/modules/flann/include/opencv2/flann/lsh_index.h, line 192.

2016-02-02 11:49:26 -0600 commented question SIGSEGV in flann getNeighbors function

@StevenPuttemans, yes I do a lot of checking on the frames. I check the frame mat for empty, I check iscontinuous then I check the descriptors mat after computing for the same checks and drop them if they fail. I also pad them with zeros to make them the same size for the index. The console shows video errors from the ffmpeg backend and I don't see any. Also ffprobe shows no errors: /usr/local/bin/ffprobe -v quiet -print_format json -show_error /Users/phire/Dropbox/Geoengineering\ 1\ hour\ vid.m4v had blank output

@berak, wait, do you mean that the data I pass to the index() call needs to be global? or at least accesible from the function that I call knnsearch from? If that's the case why wouldn't it crash every time?

2016-02-01 22:17:55 -0600 commented question SIGSEGV in flann getNeighbors function

that's just it, there is no minimal. I can try to spend the whole day tomorrow copying and pasting trying to give a compilable example so that it can be reproduced

the problem is I don't know what to leave out, because you have to run the program with the video file and it has to process it like my whole program would to get the error.

2016-02-01 17:18:13 -0600 asked a question SIGSEGV in flann getNeighbors function

UPDATE: got it working great now, I had to make the index data global and pad the query descriptors to match the index cols. Thanks all for the help

ok since this is a runtime error I am going to upload the entire qt project, which isn't that large yet, just too large to copy paste. I will also paste the partial backtrace. It is happening with one file so far, but it is the largest file. I will post a link to the file as well.

video: https://www.dropbox.com/s/e8hzpir7udp... project: https://www.dropbox.com/s/uyz0p4zck3p...

and here is the backtrace. I just have no idea what could be causing this, as it works for other videos

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x1e37 of process 1491]
0x00000001013c02df in cvflann::LshIndex<cvflann::HammingLUT>::getNeighbors(unsigned char const*, cvflann::ResultSet<int>&) () from /usr/local/opt/opencv3/lib/libopencv_flann.3.1.dylib
(gdb) backtrace
#0  0x00000001013c02df in cvflann::LshIndex<cvflann::HammingLUT>::getNeighbors(unsigned char const*, cvflann::ResultSet<int>&) () from /usr/local/opt/opencv3/lib/libopencv_flann.3.1.dylib
#1  0x00000001013bdc49 in cvflann::LshIndex<cvflann::HammingLUT>::knnSearch(cvflann::Matrix<unsigned char> const&, cvflann::Matrix<int>&, cvflann::Matrix<int>&, int, cvflann::SearchParams const&) ()
   from /usr/local/opt/opencv3/lib/libopencv_flann.3.1.dylib
#2  0x00000001013e0d1a in void cv::flann::runKnnSearch_<cvflann::HammingLUT, cvflann::Index<cvflann::HammingLUT> >(void*, cv::Mat const&, cv::Mat&, cv::Mat&, int, cv::flann::SearchParams const&) ()
   from /usr/local/opt/opencv3/lib/libopencv_flann.3.1.dylib
#3  0x00000001013b4b1a in cv::flann::Index::knnSearch(cv::_InputArray const&, cv::_OutputArray const&, cv::_OutputArray const&, int, cv::flann::SearchParams const&) ()
   from /usr/local/opt/opencv3/lib/libopencv_flann.3.1.dylib
#4  0x0000000100016334 in MainWindow::findDupes (this=0x7fff5fbff788, frame=...)
    at ../VideoTwin/mainwindow.cpp:318
#5  0x000000010001aff7 in MainWindow::on_scanwatcher_finished()::AddWrapper::operator()(MainWindow::frm&) (this=0x10641e678, data=...) at ../VideoTwin/mainwindow.cpp:298
#6  0x000000010001ae46 in QtConcurrent::MapKernel<QList<MainWindow::frm>::iterator, MainWindow::on_scanwatcher_finished()::AddWrapper>::runIteration(QList<MainWindow::frm>::iterator, int, void*) (
    this=0x10641e640, it=...)
    at /usr/local/Cellar/qt5/5.5.1_2/lib/QtConcurrent.framework/Headers/qtconcurrentmapkernel.h:63
#7  0x000000010001aed9 in QtConcurrent::MapKernel<QList<MainWindow::frm>::iterator, MainWindow::on_scanwatcher_finished()::AddWrapper>::runIterations(QList<MainWindow::frm>::iterator, int, int, void*) (this=0x10641e640, sequenceBeginIterator=..., beginIndex=6, endIndex=7)
    at /usr/local/Cellar/qt5/5.5.1_2/lib/QtConcurrent.framework/Headers/qtconcurrentmapkernel.h:72
#8  0x000000010002545a in QtConcurrent::IterateKernel<QList<MainWindow::frm>::iterator, void>::forThreadFunction() ()
#9  0x0000000100024f97 in QtConcurrent::IterateKernel<QList<MainWindow::frm>::iterator, void>::threadFunction() ()
#10 0x0000000100025072 in virtual thunk to QtConcurrent::IterateKernel<QList<MainWindow::frm>::iterator, void>::threadFunction() ()
---Type <return> to continue, or q <return> to quit---kill
#11 0x00000001045b94ac in QtConcurrent::ThreadEngineBase::run() ()
   from /usr/local/opt/qt5/lib/QtConcurrent.framework/Versions/5/QtConcurrent
#12 0x0000000103faa737 in QThreadPoolThread::run() ()
   from /usr/local/opt/qt5/lib/QtCore.framework/Versions/5/QtCore
#13 0x0000000103fadc02 in QThreadPrivate::start(void*) ()
   from /usr/local/opt/qt5/lib/QtCore.framework/Versions/5/QtCore
#14 0x00007fffa037cc13 in __FunctionTableTransposed_AVX10 ()
   from /usr/lib/system/libsystem_pthread.dylib
#15 ...
(more)
2016-01-25 20:59:39 -0600 commented question trying to search flann index getting weird errors

I've looked at the source code here: https://github.com/Itseez/opencv/blob...

but... where's the beef? it doesn't seem to do any actual work? it seems circular to me, does anyone know where the code that actually modifies dists and indices is?

2016-01-24 20:34:39 -0600 asked a question Opencv3 transparent api flann index knnsearch

ok here is what I hope is a simple question.

Does anyone know if flann uses the transparent api? In other words would I benefit from passing a UMat to flann::index::index() and flann::index::knnsearch() ?

2016-01-22 16:28:32 -0600 commented question trying to search flann index getting weird errors

That's one of the first pages that I looked at but it doesn't tell you what the format of the dists and indices mats are in. Like each row is a one byte or two byte representation of whatever. Is there nowhere to find that out

And ya that page is what I was going by trying to use the overloaded function. I tried with vector <uchar> int nothing worked

EDIT: after looking through that page again I clicked on ElementType and found: typedef L2<t>::ElementType cv::flann::Index_< T >::ElementType

and L2 has to do with sift and surf type features, so maybe that overloaded function doesn't work with binary descriptors?

2016-01-22 02:10:13 -0600 commented question trying to search flann index getting weird errors

thanks, but is there any documentation on the format of indices and dists that you can point me to?

2016-01-21 19:20:24 -0600 asked a question trying to search flann index getting weird errors

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<DescriptorExtractor> 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 ...
(more)
2016-01-20 08:19:03 -0600 received badge  Self-Learner (source)
2016-01-18 19:25:13 -0600 received badge  Scholar (source)
2016-01-18 19:08:38 -0600 answered a question copy row from one Mat to another (is it safe to pad descriptors with 0s)

got it, all I had to do was add the lines

        if (mat.rows < 500)
        mat.push_back(Mat::zeros((500 - mat.rows),32,mat.type()));
2016-01-15 19:37:53 -0600 asked a question copy row from one Mat to another (is it safe to pad descriptors with 0s)

I am putting all the descriptors for multiple images from an ORB detector into one Mat to feed to cv::flann::index->build. Here is the code I am trying.

EDIT: I guess the main question right now. Is it safe to pad the descriptors with zeros at the end to make them the same number of columns?

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();
    matonerow =  mat.reshape(1,1);
    qDebug() << "matonerow cols" << matonerow.cols << "rows" << matonerow.rows;
    indexTemp.push_back(matonerow);
    progress->setValue(iterations);
    iterations++;
    if (!indexBuilder.next())
        break;
}

the problem is that some of the descriptors are smaller, so the call to push_back fails with

OpenCV Error: Sizes of input arguments do not match () in push_back, file /tmp/opencv320160111-57911-i2x9h0/opencv-3.1.0/modules/core/src/matrix.cpp, line 834
libc++abi.dylib: terminating with uncaught exception of type cv::Exception: /tmp/opencv320160111-57911-i2x9h0/opencv-3.1.0/modules/core/src/matrix.cpp:834: error: (-209)  in function push_back

so how do I copy the one row mat to the tempindex mat? NOTE: I am using mat because I intend to convert it to UMat before passing it to build the index so I can take advantage of opencl through TAPI.

UPDATE: ok it works now but only for rows with the same amount of columns, which is no better than push_back so I still need another method!

    try
    {
        if (iterations == 1)
            indexTemp = Mat(row_count,matonerow.cols,CV_8U);

            matonerow.copyTo(indexTemp.row(iterations - 1));
    }
    catch (Exception e)
    {
        qCritical() << "failed to copy row of Mat at loop" << iterations << e.err.c_str() << e.msg.c_str();
    }

NOTE: iterations starts at 1

2016-01-12 15:38:59 -0600 commented question Flann index for video duplicate finding

those help, but what I really need now is some documentation on how to build the index with more than one image. I know it takes descriptors in the arguments, but can this be an array of arrays so each images descriptors are separate enough to tell which files match?

2016-01-10 02:01:25 -0600 edited question Flann index for video duplicate finding

I am writing a program to find duplicate videos, I am pulling frames every 500ms and using ORB to compute. I was looking at using FLANN for matching and heard about index. Reading further it says that you sacrifice accuracy, but I wonder how much. Since I am matching videos I only want 95% or higher matches of frames and will determine video matches by how many frames in common at that accuracy.

EDIT: I have been reading and see that orb is a binary descriptor and the flann matcher I was thinking of using is not for binary descriptors. Does the index even work with binary descriptors? Do I need an index or is matching binary descriptors by hamming distance fast enough not to need one?