Probleme mit OpenCV und dem FileStorage

OP #3763026
Lesenswert?
• ▲
▼
Hallo zusammen,

ich habe ein Verständnis-Problem. Zur Verdeutlichung habe ich mal ein 
Minimal-Beispiel heraus gearbeitet.

Das Problem ist, dass ich diesen Konstruktor schrieben und das Objekt 
mit einem integer als Parameter erstellen muss. Tue ich das nicht 
bekomme ich folgende Fehlermeldung:
1
In file included from C:/Programs/opencv249/opencv_bin/install/include/opencv2/core/core.hpp:4855:0,
2
                 from C:/Programs/opencv249/opencv_bin/install/include/opencv/cxcore.h:51,
3
                 from ../src/main.cpp:2:
4
C:/Programs/opencv249/opencv_bin/install/include/opencv2/core/operations.hpp: In instantiation of
5
'cv::FileStorage& cv::operator<<(cv::FileStorage&, const _Tp&) [with _Tp = MyData()]':
6
../src/main.cpp:49:21:   required from here
7
C:/Programs/opencv249/opencv_bin/install/include/opencv2/core/operations.hpp:2911:33: error: invalid
8
conversion from 'MyData (*)()' to 'int' [-fpermissive]
9
     write( fs, fs.elname, value );
10
                                 ^

Im großen und ganzen habe ich ja auch nur den Code von 
http://docs.opencv.org/doc/tutorials/core/file_input_output_with_xml_yml/file_input_output_with_xml_yml.html 
unter Explanation zusammengesetzt.
Kann mir das jemand erklären? Ich sitze hier vor einem riesen Rätsel was 
das soll.

Vielen Dank
lg Leo
Angehängte Dateien:
Gast #3763050
Lesenswert?
• ▲
▼
>> //    MyData m();  //<- funktioniert NICHT
...deklariert eine Funktion m(void), die ein MyData zurückgibt. Macht 
man das richtig mit MyData m; , funktioniert es:
1
#include "opencv/cxcore.h"
2
// g++ `pkg-config --libs --cflags opencv` 1.cpp
3
using namespace cv;
4

5
class MyData
6
{
7
public:
8
    MyData() : var(4711) {}
9
    void write(FileStorage& fs) const                        //Write serialization for this class
10
    {
11
        fs << "{" << "var" << var << "}";
12
    }
13

14
public:
15
    int var;
16
};
17

18
void write(FileStorage& fs, const std::string&, const MyData& x)
19
{
20
    x.write(fs);
21
}
22

23
int main()
24
{
25
    FileStorage fs("test.xml", FileStorage::WRITE);
26
    MyData m;
27
    fs << "test" << m;
28
    fs.release();
29
    return 0;
30
}

Antwort schreiben

Bitte melde dich an, um einen Beitrag zu schreiben.

oder

Mit Google-Account einloggen

Die Registrierung ist kostenlos und dauert nur eine Minute.

Jetzt registrieren