Ask Your Question
0

Failed to open goturn.prototxt [closed]

asked 2017-08-02 12:13:05 -0600

nrparikh gravatar image

updated 2017-08-03 08:57:43 -0600

I am using OpenCV 3.3.0 with C++ on Ubuntu 14.04. While trying to use GOTURN tracker, I am getting an error "Can't open 'goturn.prototxt' file in ReadProtoFromTextFile". Please note that I have done following steps:

  • Clone opencv, opencv_contrib repository
  • Build the library as mentioned on the official page
  • Follow the steps mentioned here

Additionally, I have also tried to build the library after cloning opencv_extra repository and setting OPENCV_TEST_DATA_PATH to opencv_extra/testdata but still, it fails (I couldn't find the caffemodel in latest branch). I cloned this repository and linked it using OPENCV_TEST_DATA_PATH and I am still getting the same error.

Also, note that I have ensured the user has all required permissions.

Please let me know if I am missing any steps while building or installing the library? If someone who has experienced this kind of error can provide steps or link the tutorial, I will really appreciate it!

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by nrparikh
close date 2017-08-09 16:46:15.220838

Comments

are you actually sure, you downloaded that file ? you need it next to your application.

berak gravatar imageberak ( 2017-08-02 19:59:18 -0600 )edit

Yes, I am pretty sure that I have both the files needed i.e. goturn.prototxt and goturn.caffemodel.

nrparikh gravatar imagenrparikh ( 2017-08-02 22:41:34 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
2

answered 2017-08-02 14:54:30 -0600

LBerger gravatar image

updated 2018-01-03 07:47:34 -0600

If you have :

Ptr<Tracker> tracker = TrackerGOTURN::create();
.....
tracker->init(img,r);

then when you call init method model goturn.prototxt is loaded here and goturn.caffemodel is loaded here. File are loaded using ifstream. I don't know linux but I think it is default directory where is your executable file.

You can check using a ifstream at the beginning of your program and try to load goturn.prototxt

When file problem is solved may be you will get this error.

my basic program to test :

#include <opencv2/opencv.hpp>
#include "opencv2/opencv_modules.hpp"
#include <opencv2/tracking.hpp>

using namespace cv;
using namespace std;


struct ParamRect {
    int rctEnCours;
    Rect r;
    Mat img;
    Mat result;
    String nomFenetre;
};



void DefRectangle(int event, int x, int y, int flags, void *userData)
{
    ParamRect *pgc = (ParamRect*)userData;
    if (pgc->img.empty())
        return;
    if (flags == EVENT_FLAG_LBUTTON)
    {
        if (pgc->rctEnCours == 0)
        {
            pgc->r.x = x;
            pgc->r.y = y;
            pgc->r.width = 0;
            pgc->r.height = 0;
            pgc->rctEnCours = 1;
        }
        else if (pgc->rctEnCours == 1)
        {
            Point tl = pgc->r.tl(), br = pgc->r.br();
            if (x != pgc->r.x)
            {
                if (x < pgc->r.x)
                {
                    pgc->r.x = x;
                    pgc->r.width = br.x - x - 1;
                }
                else
                    pgc->r.width = x - tl.x - 1;

            }
            if (y != pgc->r.y)
            {
                if (y < pgc->r.y)
                {
                    pgc->r.y = y;
                    pgc->r.height = br.y - y - 1;
                }
                else
                    pgc->r.height = y - tl.y - 1;

            }
            if (pgc->r.br().x > pgc->img.size().width)
            {
                pgc->r.width = pgc->img.size().width - pgc->r.x;
            }
            if (pgc->r.br().y > pgc->img.size().height)
            {
                pgc->r.height = pgc->img.size().height - pgc->r.y;
            }
        }
    }
    if (event == EVENT_LBUTTONUP && pgc->rctEnCours == 1)
    {
        pgc->rctEnCours = 0;
    }
    if ((flags&EVENT_FLAG_LBUTTON) != 0 && (flags & EVENT_FLAG_CTRLKEY) != 0)
    {
        pgc->r.x = x;
        pgc->r.y = y;
    }
}


int main()
{
    {
        std::ifstream fs("goturn.prototxt", std::ifstream::in); 
        if (fs.is_open()) 
            cout << "WIN"; 
        else 
            cout << "LOST";
    }
    Ptr<Tracker> tracker = TrackerGOTURN::create();
    // Open the video file
    VideoCapture capture("g:/lib/opencv/samples/data/Megamind.avi");

    if (!capture.isOpened())
        return 1;

    bool stop(false);
    ParamRect pgc;
    pgc.rctEnCours = 0;
    Mat frame; //current video frame
    pgc.img=frame;
    pgc.nomFenetre = "Extracted Frame";
    namedWindow(pgc.nomFenetre);
    int delay = 10;


    setMouseCallback(pgc.nomFenetre, DefRectangle, &pgc);

    cout << capture.get(CV_CAP_PROP_FPS);
//    capture.set(CV_CAP_PROP_POS_AVI_RATIO, 0.5);
    pgc.r= Rect(200, 150, 40, 40);
    int i=0;
    Rect2d r;
    int code = 0;
    capture >> pgc.img;
    capture >> pgc.img;
    capture >> pgc.img;
    while (code != 'g')
    {
        Mat img = pgc.img.clone();
        rectangle(img, pgc.r, Scalar(0, 255, 0), 2);
        imshow(pgc.nomFenetre, img);
        code =waitKey(10);
    }
    tracker->init(pgc.img,pgc.r);
    while (!stop)
    {
        capture>>pgc.img;
        if (tracker->update(pgc.img, r))
        {
            rectangle(pgc.img, r, Scalar(0, 0, 255), 2, 1);
            imshow(pgc.nomFenetre, pgc.img);
        }
        code = waitKey(delay);
        if (pgc.img.empty())
            stop = true;

    }

    waitKey();
}
edit flag offensive delete link more

Comments

By executable file (the file being caffe_io.cpp) you mean the source file or the executable file generated after compilation?

nrparikh gravatar imagenrparikh ( 2017-08-02 18:40:00 -0600 )edit
1

I mean you run program : ./myTrackingProgram all files must be in same repository myTrackingProgram goturn.prototxt and goturn.caffemodel

LBerger gravatar imageLBerger ( 2017-08-03 00:28:24 -0600 )edit

I added to the directory as you mentioned but it still fails with same error. Additionally, I also tried to make it run by copying it to the location of caffe_io.cpp but failed again. Is there anything that I am missing?

nrparikh gravatar imagenrparikh ( 2017-08-03 09:53:20 -0600 )edit

It does not depend of caffe_io.cpp location. Do you use a terminal to launch program ? only ./myTrackingProgram should work.

can you try just after main std::ifstream fs("goturn.prototxt", std::ifstream::in);if (fs.is_open()) cout<<"WIN"; else cout << "LOST";

LBerger gravatar imageLBerger ( 2017-08-03 10:14:58 -0600 )edit

I did just as you mentioned and it results in failure. I have ensured that permissions are correct but still, somehow the executable fails to open the file. Do you have any insight to it? I tried giving the full path to the file, it works but the question is how do I specify the path in OpenCV API?

nrparikh gravatar imagenrparikh ( 2017-08-03 12:04:38 -0600 )edit

you mean you have "win"?

LBerger gravatar imageLBerger ( 2017-08-03 13:06:58 -0600 )edit

Yes, I have "Win" if I give the full path to the file but "Lost" if I only mention the name of the file. Please note that both the files are in the same folder. The gist is if I use test script to open the file and give the full path to the file, it will open but if I add the tracker in it and then OpenCV tries to open the file it fails.

My question is that do I need to specify the path of the file? If yes then how do I let OpenCV know the path?

nrparikh gravatar imagenrparikh ( 2017-08-03 14:39:59 -0600 )edit
1

try cout < < getwd(NULL,0); and ofstream f1("toto.txt",ios_base::app); and find where is toto.txt

It is not possible to specify file path . file name are defined here It is local variable. If you want to change you have to recompile tracking moudle with full path in modelTxt and modelBin variable

LBerger gravatar imageLBerger ( 2017-08-03 15:14:55 -0600 )edit

I changed the folder in which the files were and OpenCV is able to open the files but now I am getting another error: "Requested object was not found (Requested blob ".data1" not found in setInput, file /.../src/dnn.cpp".

I went through the link you posted earlier but couldn't find the solution, do you know how to solve it?

nrparikh gravatar imagenrparikh ( 2017-08-03 15:56:47 -0600 )edit
1

try to change in lines .data1 in data1 and .data2 in data2 ( delete point)

LBerger gravatar imageLBerger ( 2017-08-03 16:25:49 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-08-02 12:13:05 -0600

Seen: 5,037 times

Last updated: Jan 03 '18