I am a beginner c++ and I have been trying to take in images from a folder as an input. Any help is welcome. I am using VScode, and the issue that push_back gives me an error stating that:
Severity Code Description Project File Line Suppression State Detail Description
Error (active) E0304 no instance of overloaded function "std::vector<_Ty, _Alloc>::push_back [with _Ty=cv::String, _Alloc=std::allocator<cv::String>]" matches the argument list HelloWorld D:\VS Projects\HelloWorld\HelloWorld\HelloWorld.cpp 103 argument types are: (WCHAR [260])
object type is: std::vector<cv::String, std::allocator<cv::String>>
Added the code below and hoping to find a solution to the issue.
#include <opencv2/opencv.hpp>
#include "opencv2\highgui.hpp"
#include "opencv2\imgproc.hpp"
#include <vector>
#include <fstream>
#include <stdio.h>
#include <iostream>
#include <Windows.h>
#include <iomanip>
#include<string.h>
using namespace cv;
using std::vector;
using std::string;
using namespace std;
char search[200];
vector<string> getNamesOfFile(string folderPath)
{
// vector of names of file within a folder
std::vector<string> names_ofFiles;
wchar_t search[200];
// convert your string search path into char array
wprintf(search, "%s*.*", folderPath.c_str());
// WIN32_FIND_DATA is a structure
// Contains information about the file that is found by the FindFirstFile
WIN32_FIND_DATAW Info;
// Find first file inside search path
HANDLE Find = ::FindFirstFileW(search, &Info);
// If FindFirstFile(search, &fd); fails return INVALID_HANDLE_VALUE,
// If Find is not equal to INVALID_HANDLE_VALUE do the loop inside the
// IF condition
if (Find != INVALID_HANDLE_VALUE) {
do {
// DWORD dwFileAttributes , FILE_ATTRIBUTE_DIRECTORY ident a directory
// If condition is fine lets push file mane into string vector
if (!(Info.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)) {
// Fill vector of names
names_ofFiles.push_back(Info.cFileName);
}
// do - while there is next file
//::FindNextFile the function succeeds, the return value is nonzero and the Info contain //information about next file
} while (::FindNextFile(Find, &Info));
::FindClose(Find);
}
// Return result
return names_ofFiles;
}
int main(int argc, const char** argv)
{
// your path where you can load all images
string Path2 = "C:\\Users\\Ksheeraja K S\\OneDrive\\Pictures\\Images";
// Vector that contain all images file mames
vector<string> vectorOfFileNameWithinPath = getNamesOfFile(Path2);
// Load all images and display
// and store inside the another vector StoredImages
int pos_count = 0;
std::vector<Mat> StoredImages;
for (int i = 0; i < vectorOfFileNameWithinPath.size() - 1; ++i)
{
// Path "C://NegativeSample/" + i th "Filename.jpg"
string cesta = Path2 + vectorOfFileNameWithinPath[i];
// Read image into Mat container
Mat img = imread(cesta, IMREAD_COLOR);
// Store images in vector you can use later for example in own ML training
StoredImages.push_back(img);
// Display single image
namedWindow("Display", WINDOW_AUTOSIZE);
imshow("Display", img);
int key1 = waitKey(10);
// Increase number of positive samples in StoredImages
// Later we push into same vector negative samples
// and we need to know, where the boundary is
pos_count = pos_count + 1;
}
}