Edit: Resolved
Currently I am having an issue with trying to use Mat framePar as a parameter in my class function findFaces. It states that the declaration is incompatible with void sampleCollection::findFaces(const error-type &framePar)
I am also having trouble with rectangle(framePar, r....); it states no instance of overloaded function "rectangle" matches the argument list. I think this might be resolved if I can fix the issue with the framePar. I'm not too sure why, there is an issue to begin with though. Below are portions of the code.
This is a portion of my sampleCollection.h:
#ifndef _SAMPLE_COLLECTION
#define _SAMPLE_COLLECTION
#include<string>
#include<opencv/cv.hpp>
#include<stdlib.h>
#include<fstream>
class sampleCollection
{
public:
sampleCollection();
//void findFaces(const Mat &framePar);
void findFaces(cv::Mat& framePar);//This is the fix for both errors.
};
#endif
This is a portion of sampleCollection.cpp file:
#include"sampleCollection.h"
#include<iostream>
#include<opencv/cv.hpp>
using namespace std;
using namespace cv;
//void sampleCollection::findFaces(const Mat &framePar)
void sampleCollection::findFaces(cv::Mat& framePar)//This is the fix for both issues.
{
vector<Rect> faces;
//Format the frames of the video for detection
cvtColor(framePar, frame_gray, COLOR_BGR2GRAY);
equalizeHist(frame_gray, frame_gray);
//Detect the face
faceDetection.detectMultiScale(frame_gray, faces, 1.1, 2, 0 | CASCADE_SCALE_IMAGE, Size(30, 30));
for (size_t i = 0; i < faces.size(); i = i + 1)
{
//Makes a rectangle boundary around the face.
Rect r = Rect(faces[i].x, faces[i].y, faces[i].width, faces[i].height);
//Draws the rectangle
rectangle(framePar, r, Scalar(255, 0, 0), 2, 8, 0);
//Collects samples
string filename = "DataSet/User" + to_string(userID) + "/User." + to_string(userID) + "." + to_string(sampleID) + ".jpg";
if (imwrite(filename, frame_gray(r)))
{
dataOut << filename << ",";
sampleID = sampleID + 1;
}
}
}
At first I had all of these code snippets in one .cpp as different functions and it worked, but it's starting to get messy, and I need to add more, so I'm trying to clean it up by putting it into classes. I need to practice using classes more often anyway.
I had read this post as well: Differences of using "const cv::Mat &", "cv::Mat &", "cv::Mat" or "const cv::Mat" as function parameters? but it's showing there is a Mat input and Mat output, I'm not sure if that will change my current issues?
I would like to, from main.cpp int main() be able to set up the camera and send frames from it's view over to the class, so that I can do all the calculations within the class.
Thank you.