When I use OpenCV 2.4,the image does not load!
In my prev problem, I found out that the image doesn't load in my project when I use OpenCV 2.4 so I couldn't create CSV file.
when I was using OpenCV 3.0.0 every thing was OK and I could load the image via imread
but now I'm using OpenCV 2.4 but the image doesn't load and always img.empty() command return true
here is my code but the img is null:
// faceRecognitionTest.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <iostream>
#include <string>
#include "opencv2\contrib\contrib.hpp"
#include "opencv2\core\core.hpp"
#include "opencv2\highgui\highgui.hpp"
#include "opencv2\objdetect\objdetect.hpp"
#include "opencv2\opencv.hpp"
#include "opencv2\imgproc\imgproc.hpp"
#include "FaceRec.h"
//file handling
#include <fstream>
#include <sstream>
using namespace std;
using namespace cv;
Mat img;
int _tmain(int argc, _TCHAR* argv[])
{
img = imread("f.jpg",CV_LOAD_IMAGE_GRAYSCALE);
if (img.empty())
{
return -1;
}
saveMatToCsv(img,"mycs.csv");
//fisherFaceTrainer();
return 0;
}
Your code looks fine. So, the thing to check will be if you are linking with the right libraries. Also, are the two versions of OpenCV compiled with the same version of Visual Studio as that makes a difference in some cases (as I discovered painfully).
you fail here
if (b=img.empty())
b will always be assigned with the img.empty() value and this operation (the assign) is ok and you will always enter the if. So forget about b, why do you need it?
The last two comments are completely incorrect. b = img.empty() will assign whatever is returned to b, and then b will be evaluated by the if statement. So if img.empty() is false then b will be set to false and you will not enter the if. The if statement is perfectly fine as is.
oops, I have made a confusion with the numbers... sorry
ok.. warning here:
if (b=img.empty())
is better ;) anyway isn't related to the issue. sorry