ifstream
을 사용하여 .txt 파일에서 값을 가져옵니다. 또한 windows
라이브러리를 사용하여 폴더의 모든 파일을 읽습니다. 폴더 끝에 도달 할 때까지 반복됩니다. 이 루프에서 txt 파일에서 값을 읽고 push_back
을 사용하여 행렬에 추가합니다.파일을 읽은 후 ifstream이 깨지는 경우
Mat trainme(0, dictionarySize, CV_32FC1);
Mat labels(0, 1, CV_32FC1); //1d matrix with 32fc1 is requirement of normalbayesclassifier class
hTrain = FindFirstFile(full_path, &TrainData);
if (hTrain != INVALID_HANDLE_VALUE)
{
ifstream file("c:\\222\\labels.txt");
string line;
do {
strcpy(loc,DirSpec);
Mat img = imread(strcat(loc,TrainData.cFileName), 0);
cout<<"Processing file: "<<TrainData.cFileName<<endl;
if (!img.data){
cout << "Image data not loaded properly: " <<TrainData.cFileName<< endl;
cin.get();
}
vector<KeyPoint> keypoints;
features->detect(img, keypoints);
if(keypoints.empty()) cout<<"Cannot find keypoints in image: "<<TrainData.cFileName<<endl;
Mat bowDescriptor;
bowDE.compute(img, keypoints, bowDescriptor);
trainme.push_back(bowDescriptor);
getline(file, line);
labels.push_back(line);
strcpy(loc,"");
} while(FindNextFile(hTrain,&TrainData));
}
문제는 3 개 루프 다음 줄 labels.push_back(line);
에서 발생 : 여기
Access violation writing location
이라는 뜻입니다. 그리고이 라인을 가리키며
memcpy.asm
:
mov [edi],al ;U - put byte in destination
나는 그것이 실패한 이유를 알 수 없다. 내가 float value = atof(line)
을 사용 했으므로 string
형식을 전송하는 것이 문제 일 수 있다고 생각했으나 문자열 형식을 변환 할 수없고 이전 C 스타일 문자열 만 사용할 수 있다는 오류가있었습니다. 여기
는
1
2
2
2
1
2
2
2
보고 주셔서 감사합니다 labels.txt에 포함되어있는 것입니다.
업데이트 : 파일을 주 루프에서 이동하고 사용하려고 시도했습니다. while(file.good())
하지만 같은 위치에서 동일한 오류가 발생합니다. 나는 이유를 모른다.
string line;
ifstream file("c:\\222\\labels.txt");
if (file.is_open())
{
while (file.good())
{
getline (file,line);
labels.push_back(line);
}
file.close();
}
'매트'유형의 정의는 무엇입니까? – phonetagger
@phonetagger''cv :: Mat''처럼 opencv의 기능입니다. – ipunished