在 C++ 中写入 csv 文件失败

wrting to csv file in c++ fails

我正在使用本应检测人脸的代码。该代码工作得很好,但是一旦我尝试插入三行以写入 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()

您忘记结束这一行 cout<< "In while"<<

您代码中的某处是这个片段

out<< "In while"<<
// Capture a frame
~~~~~~~~~~~~~~~~~~
cap >> frame;

你应该尝试从上到下修复错误。第一个错误是关于 coutoperator<<cv::VideoCapture cap.