Ask Your Question
0

Retina Demo - segmentation fault

asked 2013-05-25 04:20:29 -0600

rawesfa gravatar image

updated 2013-05-25 06:16:08 -0600

Hello, I'm trying to run tutorial code from opencv 2.4.5 to retina model and after my little modification it goes like that:

#include <iostream>
#include <cstring>

#include "opencv2/opencv.hpp"

using namespace cv;

static void help(std::string errorMessage)
{
    std::cout<<"Program init error : "<<errorMessage<<std::endl;
    std::cout<<"\nProgram call procedure : retinaDemo [processing mode] [Optional : media target] [Optional LAST parameter: \"log\" to activate retina log sampling]"<<std::endl;
    std::cout<<"\t[processing mode] :"<<std::endl;
    std::cout<<"\t -image : for still image processing"<<std::endl;
    std::cout<<"\t -video : for video stream processing"<<std::endl;
    std::cout<<"\t[Optional : media target] :"<<std::endl;
    std::cout<<"\t if processing an image or video file, then, specify the path and filename of the target to process"<<std::endl;
    std::cout<<"\t leave empty if processing video stream coming from a connected video device"<<std::endl;
    std::cout<<"\t[Optional : activate retina log sampling] : an optional last parameter can be specified for retina spatial log sampling"<<std::endl;
    std::cout<<"\t set \"log\" without quotes to activate this sampling, output frame size will be divided by 4"<<std::endl;
    std::cout<<"\nExamples:"<<std::endl;
    std::cout<<"\t-Image processing : ./retinaDemo -image lena.jpg"<<std::endl;
    std::cout<<"\t-Image processing with log sampling : ./retinaDemo -image lena.jpg log"<<std::endl;
    std::cout<<"\t-Video processing : ./retinaDemo -video myMovie.mp4"<<std::endl;
    std::cout<<"\t-Live video processing : ./retinaDemo -video"<<std::endl;
    std::cout<<"\nPlease start again with new parameters"<<std::endl;
    std::cout<<"****************************************************"<<std::endl;
    std::cout<<" NOTE : this program generates the default retina parameters file 'RetinaDefaultParameters.xml'"<<std::endl;
    std::cout<<" => you can use this to fine tune parameters and load them if you save to file 'RetinaSpecificParameters.xml'"<<std::endl;
}

int main(int argc, char* argv[]) {
    bool useLogSampling = false; // "log" // check if user wants retina log sampling processing
    std::string inputMediaType="-image"; // argv[1]
    string imageOrVideoName = "lenka.jpg"; // argv[2]


    // declare the retina input buffer... that will be fed differently in regard of the input media
    Mat inputFrame, image;
    VideoCapture videoCapture; // in case a video media is used, its manager is declared here

    if (!strcmp(inputMediaType.c_str(), "-image") )
    {
        std::cout<<"RetinaDemo: processing image "<<imageOrVideoName<<std::endl;
        inputFrame = imread(imageOrVideoName, 0); // load image in RGB mode
    }else{
        if (!strcmp(inputMediaType.c_str(), "-video"))
        {
            if (useLogSampling) // attempt to grab images from a video capture device
            {
                videoCapture.open(0);
            }else// attempt to grab images from a video filestream
            {
                std::cout<<"RetinaDemo: processing video stream "<<imageOrVideoName<<std::endl;
                videoCapture.open(imageOrVideoName);
            }
            // grab a first frame to check if everything is ok
            videoCapture>>inputFrame;
        }
    else
        {
            help("bad command parameter");
            return -1;
        }
    }
    if (inputFrame.empty())
    {
        help("Input media could not be loaded, aborting");
        return -1;
    }

    try
    {
        // create a retina instance with default parameters setup, uncomment the initialisation you wanna test
        Ptr<Retina> myRetina;

        // if the last parameter is 'log', then activate log sampling (favour foveal vision and subsamples peripheral vision)
        if (useLogSampling)
        {
             myRetina = new cv::Retina(inputFrame.size(), true, cv::RETINA_COLOR_BAYER, true, 2.0, 10.0);
        }
        else// -> else ...
(more)
edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2013-10-30 08:46:43 -0600

gigaVolter gravatar image

i have similar to ts problem (don't want to start new topic), but i didn't change anything in sample code... I'm trying it on Win7, vs 2010 c++. OpenCV 2.4.6, and 2.4.4... When debuger hits myRetina->run(...), i have exception in taskCollection.cpp (located at 'C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC\crt\src\TaskCollection.cpp') on row 'pChore->m_pFunction(pChore);' id don't know what to do... plz help

edit flag offensive delete link more

Comments

All what i done - download last version of opencv and compile it with tbb support. This can solve problem

gigaVolter gravatar imagegigaVolter ( 2013-10-31 00:31:56 -0600 )edit
0

answered 2013-05-25 05:33:37 -0600

berak gravatar image

updated 2013-05-25 05:52:34 -0600

oh, you must not modify argc/argv ! (if you did not supply args there, argv[] only holds 1 string, the progname. assigning to argv[1], argv[2] or such will overflow, and invoke nasal demons! )

either supply the required args on the cmdline (and leave the original argv-code intact)

or replace all occurences with "real" strings

int main(int argc, char* argv[]) {
    bool useLogSampling = false; // "log" // check if user wants retina log sampling processing
    std::string inputMediaType="-image"; // argv[1]
    string imageOrVideoName = "lenka.jpg"; // argv[2]


    // declare the retina input buffer... that will be fed differently in regard of the input media
    Mat inputFrame, image;
    VideoCapture videoCapture; // in case a video media is used, its manager is declared here

    if (!strcmp(inputMediaType.c_str(), "-image") )
    {
        std::cout<<"RetinaDemo: processing image "<<imageOrVideoName<<std::endl;
        inputFrame = imread(imageOrVideoName, 0); // load image in RGB mode
    }else{
        if (!strcmp(inputMediaType.c_str(), "-video"))
        {
            if (useLogSampling) // attempt to grab images from a video capture device
            {
                videoCapture.open(0);
            }else// attempt to grab images from a video filestream
            {
                std::cout<<"RetinaDemo: processing video stream "<<imageOrVideoName<<std::endl;
                videoCapture.open(imageOrVideoName);
            }
            // grab a first frame to check if everything is ok
            videoCapture>>inputFrame;
        }
    }
edit flag offensive delete link more

Comments

you are right, that was just my sloppiness to make things faster. anyway, i still get segmentation fault.

rawesfa gravatar imagerawesfa ( 2013-05-25 06:14:59 -0600 )edit

code works for me!

(had to use createRetina() instead of new, because i'm on 2.4.9)

so, please check again, if your image was loaded properly !

berak gravatar imageberak ( 2013-05-25 06:39:47 -0600 )edit

displaying image with imshow works well. so if it works for you with createRetina(), then there is a problem when creating myRetina. btw. where did you get 2.4.9, when the newest is 2.4.5 on opencv.org?

rawesfa gravatar imagerawesfa ( 2013-05-25 06:54:58 -0600 )edit
  1. yep, if you can see your img, then it's obviously loaded properly ;)
  2. building from github master src.

    but i can't really recommend that, has still a couple of bugs in the cmake-related stuff

berak gravatar imageberak ( 2013-05-25 07:08:36 -0600 )edit

How about you simply start your program in debug (don't forget to supply the file names yourself instead of looking at argc/argv!) and look where the program shuts down? That's what debuggers are for, finding those kinds of problems.

Notas gravatar imageNotas ( 2013-05-25 10:10:07 -0600 )edit

How do you invoke createRetina() on 2.4.9?

Grecd gravatar imageGrecd ( 2014-06-26 06:08:35 -0600 )edit

Question Tools

Stats

Asked: 2013-05-25 04:20:29 -0600

Seen: 1,690 times

Last updated: Oct 30 '13