Commit c7057bf1 authored by li412076173's avatar li412076173

add IrisDataStorage

parent 48b7c395
......@@ -33,6 +33,7 @@
#include "MousePositionProvider.h"
#include "Recorder.h"
#include "RecordManager.h"
#include "IrisDataStorage.h"
#define debugcout(x) std::cout<<#x<<x<<std::endl
......
#include "irisDataStorage.h"
#include <fstream>
using namespace std;
using namespace cv;
void wirteIrisData(const std::string & prefix, const std::vector<cv::Mat> & matVec, const std::vector<std::vector<cv::Point2f>> & contourVec, const double & eyeRadius, const std::vector<cv::Vec3d> & eyeCenters, const std::vector<cv::RotatedRect> & eyeRotatedRects, const cv::Matx44d & transformFaceToFrontCamera) {
int count = matVec.size();
for (int i = 0; i < count; i++) {
string filename = prefix + std::to_string(i) + "_irisData.txt";
string picname = prefix + std::to_string(i) + "_eyeImages.jpg";
imwrite(picname,matVec[i]);
ofstream out(filename, ios::trunc);
out << contourVec[i].size() << endl;
for (Point2f j : contourVec[i]) {
out << j.x << " " << j.y << " ";
}
out << endl;
out << eyeRadius << endl;
out << eyeCenters[i][0] << " " << eyeCenters[i][1] << " " << eyeCenters[i][2] << endl;
out << eyeRotatedRects[i].center.x << " " << eyeRotatedRects[i].center.y << " ";
out << eyeRotatedRects[i].size.width << " " << eyeRotatedRects[i].size.height << " ";
out << eyeRotatedRects[i].angle << endl;
for (int j = 0; j < 4; j++) {
for (int k = 0; k < 4; k++) {
out << transformFaceToFrontCamera.val[j*4 + k] << " ";
}
}
out << endl;
out.close();
}
}
bool fileExists(std::string filename) {
ifstream fin(filename);
if (!fin)
return false;
else
return true;
}
bool readIrisData(const std::string & prefix, std::vector<cv::Mat> & matVec, std::vector<std::vector<cv::Point2f>> & contourVec, double & eyeRadius, std::vector<cv::Vec3d> & eyeCenters, std::vector<cv::RotatedRect> & eyeRotatedRects, cv::Matx44d & transformFaceToFrontCamera) {
int i = 0;
matVec = std::vector<cv::Mat>();
contourVec = std::vector<std::vector<cv::Point2f>>();
eyeCenters = std::vector<cv::Vec3d>();
eyeRotatedRects = std::vector<cv::RotatedRect>();
transformFaceToFrontCamera = cv::Matx44d::zeros();
if (!fileExists(prefix + std::to_string(i) + "_irisData.txt") && fileExists(prefix + std::to_string(i) + "_eyeImages.jpg")) {
return false;
}
while (fileExists(prefix + std::to_string(i) + "_irisData.txt") && fileExists(prefix + std::to_string(i) + "_eyeImages.jpg")) {
Mat tmp = imread(prefix + std::to_string(i) + "_eyeImages.jpg");
matVec.push_back(tmp);
ifstream out(prefix + std::to_string(i) + "_irisData.txt");
int size = 0;
out >> size;
std::vector<cv::Point2f> points(0);
for (int j = 0; j < size;j++) {
float x, y;
out >> x >> y;
points.push_back(Point2f(x,y));
}
contourVec.push_back(points);
out >> eyeRadius;
double x, y, z;
out >> x >> y >> z;
eyeCenters.push_back(Vec3d(x, y, z));
float t1, t2, angle;
out >> t1 >> t2;
Point2f center(t1,t2);
out >> t1 >> t2;
Size2f sizet(t1, t2);
out >> angle;
eyeRotatedRects.push_back(RotatedRect(center, sizet, angle));
for (int j = 0; j < 4; j++) {
for (int k = 0; k < 4; k++) {
out >> transformFaceToFrontCamera.val[j * 4 + k];
}
}
out.close();
i++;
}
return true;
}
\ No newline at end of file
#pragma once
#include <opencv2/opencv.hpp>
void wirteIrisData(const std::string & prefix, const std::vector<cv::Mat> & matVec, const std::vector<std::vector<cv::Point2f>> & contourVec, const double & eyeRadius, const std::vector<cv::Vec3d> & eyeCenters, const std::vector<cv::RotatedRect> & eyeRotatedRects,const cv::Matx44d & transformFaceToFrontCamera);
bool readIrisData(const std::string & prefix, std::vector<cv::Mat> & matVec, std::vector<std::vector<cv::Point2f>> & contourVec, double & eyeRadius, std::vector<cv::Vec3d> & eyeCenters, std::vector<cv::RotatedRect> & eyeRotatedRects, cv::Matx44d & transformFaceToFrontCamera);
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment