Compilation error while reading a cv::Mat from a cv::FileNode without temporary variable

☆樱花仙子☆ 提交于 2019-12-24 04:45:05

问题


I have a piece of code that saves a row of a cv::Mat onto a file using OpenCV FileStorage API. I'm trying to read this matrix onto a row without using a temporary variable that points to the row itself. The code that does this job is the following:

#include <opencv2/highgui/highgui.hpp>

using namespace cv;

int main(int argc, char **argv) {
    Mat src = imread(argv[1], -1);

    FileStorage fs("test.yml", FileStorage::WRITE);
    fs << "imgs" << "[" << "{" << "img" << src.row(500) << "}" << "]";
    fs.release();

    FileStorage fs2("test.yml", FileStorage::READ);
    Mat src2(src.size(), src.type(), Scalar(0));
    FileNode imgsNode = fs2["imgs"];
    for (FileNodeIterator it = imgsNode.begin(); it != imgsNode.end(); ++it)
        (*it)["img"] >> src2.row(500);
    fs2.release();

    imwrite("res.pgm", src2);
}

I'm trying to compile it using the following Makefile:

# Makefile for Test

CXX = g++

CXXFLAGS = -O2 -g -Wall -fmessage-length=0 -std=c++0x
LDFLAGS =

# OpenCV
CXXFLAGS += `pkg-config opencv --cflags`
LDFLAGS += `pkg-config opencv --libs`

SOURCES = $(wildcard *.cpp)
OBJECTS = $(SOURCES:.cpp=.o)

BIN = Test

all: $(BIN)

$(BIN): $(OBJECTS)
    $(CXX) $(OBJECTS) -o $(BIN) $(LDFLAGS)

.cpp.o:
    $(CXX) -c $(CXXFLAGS) $< -o $@

clean:
    rm -rf $(OBJECTS) $(BIN) *~

When I try to compile, it throws the following error:

Test.cpp:23:31: error: no match for ‘operator>>’ in ‘cv::FileNode::operator[](const char*) const(((const char*)"img")) >> cv::Mat::row(int) const(500)’

This question is derived from the answer to this other SO question where this code is claimed to work.

My system is an Ubuntu 12.10 over a x86_64 architecture. I'm using g++ 4.7.2 as compiler and OpenCV 2.4.6.1 bundled with ROS Groovy which I installed through the PPA.

I tried as well with OpenCV 2.3.1 from my distro repositories as well as with OpenCV 2.4.2 from a PPA but got the same result. On each OpenCV installation I have all the available libraries.

Thank you very much about any insight.

来源:https://stackoverflow.com/questions/20107813/compilation-error-while-reading-a-cvmat-from-a-cvfilenode-without-temporary

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!