I hope somebody can help me with this problem as I am new to opencv as well as sqlite database. I have got problem regarding my code on how to use the blob image from sqlite database to recognize face using template matching. I have successfully store the image into dbase using blob- from mat image:
QString fileName = QFileDialog::getOpenFileName(this,tr("Open Image"), "C://Users//yana//Desktop//Detected Faces//",tr("Image Files (*.png *.jpg *.jpeg *.bmp)"));
tpl = cv::imread(fileName.toLatin1().data());
QImage TImg(fileName);
// load image to bytearray
QFile f(fileName);
if(f.open(QIODevice::ReadOnly))
{
ba = f.readAll();
f.close();
}
So here is where the problem starts. So in order to recognize face, I used cv mat image - cv:: Mat tpl. I have retrieve the image from database and convert it to mat image but it did not work. When I did the face recognition, the program suddenly crashed and got error "OpenCV Error: Assertion failed ((img.depth() == CV_8U || img.depth() == CV_32F) && img.type() == templ.type()) in cv::matchTemplate". This is my code for retrieving blob image from database and convert it to mat image:
QSqlQuery qry;
qry.prepare("SELECT TImg FROM TemplateInfo WHERE FaceID='"+Faceid+"'");
qry.exec();
qry.next();
QByteArray ba1 = qry.value(5).toByteArray();
QImage img = QImage();
img.loadFromData(ba1);
tpl= cv::Mat(img.height(), img.width(), CV_LOAD_IMAGE_GRAYSCALE, (uchar*)img.bits(), img.bytesPerLine());
Can anybody please help me solve on how to read blob image from sqlite and convert it to mat to further the face recognition? :( thank you.
Aucun commentaire:
Enregistrer un commentaire