I'm attempting to create an SVM classifier that trains from images in a couple folders. I'm able to get the images fine, but when I followed another post to create the training image, I put an imshow at the end to see what it looked like and it is just a fully white image. Is that normal, or have I done something wrong?
Here is my code:
//List of files in each training directory
std::vector<cv::String> ltvFiles;
std::vector<cv::String> mtvFiles;
std::vector<cv::String> htvFiles;
//Get the training image file names
cv::glob("data/training/ltv", ltvFiles);
cv::glob("data/training/mtv", mtvFiles);
cv::glob("data/training/htv", htvFiles);
//Number of files across all directories
int numFiles = ltvFiles.size() + mtvFiles.size() + htvFiles.size();
//Look at one image to get the area (assuming all the other images are the same size)
cv::Mat sample = cv::imread(ltvFiles[0]);
int imgArea = sample.rows * sample.cols;
sample.release();
//Create the training matrix with numFiles rows and imgArea columns
cv::Mat trainingMat(numFiles, imgArea, CV_32FC1);
cv::Mat img;
int col = 0;
//go through LTV images first
for (int image = 0; image < ltvFiles.size(); image++) {
//Open the next image
img = cv::imread(ltvFiles[image], 0);
//Start in the first column
col = 0;
//Iterate through each pixel in the opened image and place it in the next location in the current row
for (int y = 0; y < img.rows; y++) {
for (int x = 0; x < img.cols; x++) {
trainingMat.at<float>(image, col++) = img.at<uchar>(y, x);
}
}
}
//Skipping code for MTV and HTV
//Show the result
cv::imshow("Training image", trainingMat);
I'm wondering if it has something to do with this line in the bottom for loop
trainingMat.at<float>(image, col++) = img.at<uchar>(y, x);
Is the uchar to float a problem?