Cannot Run Code To Use Webcam capture and analysis

asked 2019-03-27 23:05:35 -0600

turiya gravatar image

updated 2019-04-03 22:09:36 -0600

Hello everyone, Im using Visual Studio environment with OpenCV to run an analaysis on mosquito behaviours suing openCV for my final year thesis project.

I tried running the code files but a few errors showed up. could you guide me where i might be going wrong? thanks.

below are the error.

Error C1010 unexpected end of file while looking for precompiled header. Did you forget to add '#include "pch.h"' to your source? projet file c:\users\owner\source\repos\projet file\projet file\projet file.cpp 285

======================================================================

These are the codes for your reference. I think its a small issue i need to fix but im unsure because im really new to this environment. hope you guys could guide me. thanks alot .

  #include <opencv2\highgui.hpp>
    #include <opencv2\videoio.hpp>
    #include <opencv2\imgcodecs.hpp>
    #include "opencv2/imgproc/imgproc.hpp"
    #include <opencv2/opencv.hpp>
    #include <stdlib.h>
    #include <stdio.h>
    #include <iostream>

#include <math.h>
#include <ctime>
#include <opencv2\core\ocl.hpp>
#include <fstream>
#include <direct.h>
#include <shlobj.h>
#include <stdarg.h>
#include <ctype.h>


//ADD this to disable OpenCL explicitly
using namespace cv;
using namespace std;
void Detector(Mat Img, int x_, int y_)
{
    circle(Img, Point(x_, y_), 2, Scalar(0, 255, 0), 2, 8, 0);
}
void AvgDetector(Mat Img, int x_, int y_)
{
    circle(Img, Point(x_, y_), 2, Scalar(0, 0, 255), 2, 8, 0);
}
void Alert(Mat Img){
    putText(Img, "Detected", Point(20, 20), FONT_HERSHEY_PLAIN, 1, Scalar::all(255), 2, 8);
}
const string currentDateTime() {
    time_t     now = time(0);
    struct tm  tstruct;
    char       buf[80];
    tstruct = *localtime(&now);
    strftime(buf, sizeof(buf), "%Y-%m-%d.%X", &tstruct);

    return buf;
}
void GetDesktopResolution(int& horizontal, int& vertical)
{
    RECT desktop;
    // Get a handle to the desktop window
    const HWND hDesktop = GetDesktopWindow();
    // Get the size of screen to the variable desktop
    GetWindowRect(hDesktop, &desktop);
    // The top left corner will have coordinates (0,0)
    // and the bottom right corner will have coordinates
    // (horizontal, vertical)
    horizontal = desktop.right;
    vertical = desktop.bottom;
}
string ExePath() {
    char buffer[MAX_PATH];
    GetModuleFileNameA(NULL, buffer, MAX_PATH);
    string::size_type pos = string(buffer).find_last_of("\\/");
    return string(buffer).substr(0, pos);
}


int main()
{
    string Location, Avg_Position, Datapath, Maxfreq, Version;
    ofstream myfile;
    stringstream DataDir, datafilename, Position;
    bool CreateDir = true;

    int StringElement = 0;
    string s = ExePath();
    std::string delimiter = "\\";
    size_t pos = 0;
    std::string token;
    while ((pos = s.find(delimiter)) != std::string::npos) {
        StringElement++;
        token = s.substr(0, pos);
        if (StringElement == 7){
            Version = token;
            break;
        }
        s.erase(0, pos + delimiter.length());
    }

    cout << CV_VERSION << "\n";
    cout << Version << "\n\n";
    cout << "Please key-in the location of your testing site: \n";
    cout << "Location:\t";
    getline(cin, Location);
    cout << "\nPlease key-in the path for the data files to be saved: \n";
    cout << "Path:\t";
    getline(cin, Datapath);
    cout << "\nPlease select start once the system is ready. \n\n";


    // Disable OpenCL explicitly here
    ocl::setUseOpenCL(false);
    VideoCapture capture(2);
    Mat current_frame, Gray_frame, Black_White, Black, Test;



    /////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
    //Trackbar region   /////////////////////////////////////////////////////////////////////////////////////////////////////
    //// For cropper
    int a = 0, b = 0, c = 0, d = 0 ...
(more)
edit retag flag offensive close merge delete

Comments

the errors shown are unrelated to any opencv code,

problem here is your usage of c-api / windows functions, and your char* pointers.

berak gravatar imageberak ( 2019-03-28 00:50:35 -0600 )edit

also try to disable "precompiled headers" in your project.

berak gravatar imageberak ( 2019-03-30 04:03:22 -0600 )edit

Hi sir, i fixed the first problem with char by adding const char*

But for the next one, if i removed the precompiled headers, it shows more errors.

turiya gravatar imageturiya ( 2019-04-04 02:40:01 -0600 )edit