Vector of int to Mat
Hello, I am new at OpenCV. I'm trying to convert a vector of int to Mat but the program always crash. I read from a file the first line that contains a number and the image's pixels, the data is saved in dadosString that is a vector<string>. Next I use the method StringToIn to convert the all the strings to int, so far everything works, but when I try to create a Mat it crash.
File: 6, 60 16 53 31 25 26 25 71 84 80 89 99 106 117 124 135 144 154 159 166 178 183 189 194 196 199 ...
6 - is the number of image
The rest o the numbers are the image 48x48.
Split the string read from file:
vector<string> splitString(const string& line, const string& symbol) {
vector<string> sliceString;
size_t start = 0;
size_t end = 0;
while (start != string::npos && end != string::npos) {
start = line.find_first_not_of(symbol, end);
if (start != string::npos) {
end = line.find_first_of(symbol, start);
if (end != string::npos) {
sliceString.push_back(line.substr(start, end - start));
}
else {
sliceString.push_back(line.substr(start));
}
}
}
return sliceString;
Convert the string into vector<int>:
vector<int> StringToInt(string& dados1){
vector<string> dados = splitString(dados1, " ");
vector<int> dadosInt(dados.size());
int i;
for (i = 0; i < dados.size(); i++){
dadosInt[i] = atoi(dados[i].c_str());
}
return dadosInt;
The main:
ifstream infile;
string read_file_name("D:\\datasets\\kaggle_facial_expression\\treino.csv");
infile.open(read_file_name);
string sLine;
getline(infile, sLine);
infile.close();
vector<string> dadosString = splitString(sLine,",");
vector<int> dadosInt = StringToInt(dadosString[1]);
Mat M = Mat(48,48,CV_8UC1);
Anyone has an idea?
can you give us a bit more context (code) ?
why do you have a
vector<int>
in the 1st place ?As you asked I gave more code.
please try with a
vector<uchar>
, not avector<int>
I tried to use
vector<uchar>
but doesn't work"but doesn't work" is never helpful. don't be that lame. if there are errors, we need to see them.
When I try to run it with debugger, I using the Visual Studio 2013, I get this error "The application was unable to start correctly (0xc000007b)". Apparently I have the include and lib correctly linked. btw thanks for spend time with me
"Apparently I have the include and lib correctly linked" -- please doubl check again. also, make sure, you got the path to the resp. set of dlls in your system-wide PATH env var.
is it this ?
No, it is this.