Reputation: 33
I am having problems getting the << operator to work for cout and writing to a FileStorage object in Visual studio c++ 2010 express. I am using the vs10 libraries, included the ***d.lib files and am running my project in debug mode. Other opencv functions (ORB, imshow) seem to work
When I use the << operator for printing a matrix with cout I get an access violation error.
The second issue I am having is when I try to write a matrix to a FileStorage object. I can write 1 matrix and read it from the file without it crashing. When I however try to write 2 matrices I get an "Exception at memory location" error on the second write. The console error says that No element name has been given.
The code I used for testing:
cv::Mat test(3,3,CV_8UC1);
cv::FileStorage file("fudge.xml", cv::FileStorage::WRITE);
for(int x=0;x<3;x++){
for(int y=0;y<3;y++){
test.at<unsigned char>(x,y) = x+y;
}
}
std::cout<<test<<std::endl;
file << "rotMat1" << test;
file << "rotMat2" << test;
Code Update
this is my entire code
#include "stdafx.h"
#include <opencv2\core\core.hpp>
#include <iostream>
int _tmain(int argc, _TCHAR* argv[])
{
cv::Mat test(3,3,CV_8UC1);
cv::Mat test2(3,3,CV_8UC1);
cv::FileStorage file("fudge.xml", cv::FileStorage::WRITE);
for(int x=0;x<3;x++){
for(int y=0;y<3;y++){
test.at<unsigned char>(x,y) = x+y;
test2.at<unsigned char>(2-x,2-y) = x+y;
}
}
std::cout<<test<<std::endl; //error 1
file << "AAAAA" << test;
file << "BBBBB" << test2; //error 2
return 0;
}
both errors still occur
UPDATE, I fixed it (kind of)
I found the problem but now there is a new one. So the problem was that because I have projects in both VS2010 and VS2012. Because of this I added both vs10/bin and vs11/bin to the path variables. It turns out that this results in visual studio using vs11/bin (maybe because that was declared first). After removing the vs11/bin decleration it worked in vs2010 but now vs2012 is broken. Because this isn't part of the original problem I will set it as answered.
Upvotes: 1
Views: 1866
Reputation: 33
The problem was that because I have projects using opencv in both visual studio 2010 and 2012 I added both /dir paths to the environment path variable. This resulted in visual studio always using the 2012/dir (probably because this was declared first). After removing the 2012/dir it worked fine.
Upvotes: 1
Reputation: 650
I don't think the namespace is the problem. Two things that I could think off that cause the problem:-
Upvotes: 0
Reputation: 546
you need to add using namespace cv;
follow this exemple : http://docs.opencv.org/modules/core/doc/xml_yaml_persistence.html#xml-yaml-file-storages-writing-to-a-file-storage
Upvotes: 0