【发布时间】:2020-10-22 18:46:29
【问题描述】:
我正在使用应该检测人脸的代码。代码工作得很好,但是当我尝试插入三行写入 csv 文件时,它会因大约 100 多行的冗长错误而崩溃 -ERROR FILE LOG。
此代码取自:- https://github.com/shunyaos/shunyaface
// Header file for Face-Recognition/Detection
#include "shunyaface.h"
#include "opencv2/opencv.hpp"
#include <bits/stdc++.h>
#include "fstream"
using namespace std;
using namespace cv;
int main(int argc, char** argv){
// Create instance of class FaceRec
std::ofstream filename("test.csv");
filename<< "TESTING CSV WRITE";
FaceRec facerec;
Mat frame;
Mat frame2;
clock_t start, end; //This will hold the start and end-time
int count = 0; //Variable which hold the number of frames elapsed
VideoCapture cap(0);
time(&start);
while(1)
{
// Capture a frame
cap >> frame;
// Pass the frame to the detect function which will return the frame with a bounding-box on the face and points on the lips and eyes
frame2 = facerec.detect(frame);
count++; //Increment count
// Display the frame to the user
imshow("face-detect", frame2);
if(waitKey(1) == 'q')
break;
}
time(&end); // Stop the time
cout<< "Output FPS is:"<<count/(end-start)<<endl; //Display Output-FPS
filename.close();
return 0;
}
所以基本上如上所示,在包含这些行之后,代码被破坏了:-
std::ofstream filename("test.csv");
filename<< "TESTING CSV WRITE";
filename.close()
【问题讨论】:
-
"它出现了大约 100 多行的冗长错误。" 请包括所述错误。
-
请创建一个minimal reproducible example 并将其发布在您的问题中。错误文件的链接指向 404 not found。您在阅读 CSV 时遇到问题。你为什么发布包含opencv的代码?不相关。
-
尝试#include
而不是“fstream”。 -
@stefan.gal
<fstream>而不是"fstream"的性能要好一些,但编译器会搜索它在前一种情况下会搜索的所有位置。使用"fstream",编译器将额外搜索相对于源文件的内容。 -
您是否忘记结束这一行
cout<< "In while"<<?您应该尝试从上到下修复错误。第一个错误是关于cout、operator<<和cv::VideoCapture cap
标签: c++ opencv image-processing face-detection