Skip to content

Commit

Permalink
never save src, too big and not necessary
Browse files Browse the repository at this point in the history
  • Loading branch information
meiqua committed Feb 26, 2019
1 parent b66afcc commit b3bee53
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 34 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ project(shape_based_matching)


# debug or release
SET(CMAKE_BUILD_TYPE "Release")
#SET(CMAKE_BUILD_TYPE "Debug")
#SET(CMAKE_BUILD_TYPE "Release")
SET(CMAKE_BUILD_TYPE "Debug")


# arm or x86
Expand Down
34 changes: 8 additions & 26 deletions line2Dup.h
Original file line number Diff line number Diff line change
Expand Up @@ -215,25 +215,25 @@ class shapeInfo_producer{
float scale_step = 0.5;
float eps = 0.00001f;

class shape_and_info{
class Info{
public:
cv::Mat src;
cv::Mat mask;
float angle;
float scale;
shape_and_info(cv::Mat src_, cv::Mat mask_, float angle_, float scale_){
Info(cv::Mat src_, cv::Mat mask_, float angle_, float scale_){
src = src_;
mask = mask_;
angle = angle_;
scale = scale_;
}

shape_and_info(float angle_, float scale_){
Info(float angle_, float scale_){
angle = angle_;
scale = scale_;
}
};
std::vector<shape_and_info> infos;
std::vector<Info> infos;

shapeInfo_producer(cv::Mat src, cv::Mat mask = cv::Mat()){
this->src = src;
Expand All @@ -254,48 +254,30 @@ class shapeInfo_producer{

return dst;
}
static void save_infos(std::vector<shapeInfo_producer::shape_and_info>& infos, std::string path = "infos.yaml",
bool save_src = false){
static void save_infos(std::vector<shapeInfo_producer::Info>& infos, std::string path = "infos.yaml"){
cv::FileStorage fs(path, cv::FileStorage::WRITE);

fs << "save_src" << save_src;

fs << "infos"
<< "[";
for (int i = 0; i < infos.size(); i++)
{
fs << "{";

if(save_src){
fs << "src" << infos[i].src;
fs << "mask" << infos[i].mask;
}
fs << "angle" << infos[i].angle;
fs << "scale" << infos[i].scale;
fs << "}";
}
fs << "]";
}
static std::vector<shape_and_info> load_infos(std::string path = "info.yaml"){
static std::vector<Info> load_infos(std::string path = "info.yaml"){
cv::FileStorage fs(path, cv::FileStorage::READ);

std::vector<shape_and_info> infos;

bool save_src;
fs["save_src"] >> save_src;
std::vector<Info> infos;

cv::FileNode infos_fn = fs["infos"];
cv::FileNodeIterator it = infos_fn.begin(), it_end = infos_fn.end();
for (int i = 0; it != it_end; ++it, i++)
{
if(save_src){
cv::Mat src, mask;
(*it)["src"] >> src;
(*it)["mask"] >> mask;
infos.emplace_back(src, mask, float((*it)["angle"]), float((*it)["scale"]));
}else{
infos.emplace_back(float((*it)["angle"]), float((*it)["scale"]));
}
infos.emplace_back(float((*it)["angle"]), float((*it)["scale"]));
}
return infos;
}
Expand Down
11 changes: 6 additions & 5 deletions test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ void scale_test(){
shapes.scale_step = 0.01f;
shapes.produce_infos();

std::vector<shape_based_matching::shapeInfo_producer::shape_and_info> infos_have_templ;
std::vector<shape_based_matching::shapeInfo_producer::Info> infos_have_templ;
string class_id = "circle";
for(auto& info: shapes.infos){

Expand All @@ -165,9 +165,9 @@ void scale_test(){
// save templates
detector.writeClasses(prefix+"case0/%s_templ.yaml");

// save infos, last bool is to save src or not, default false
// save infos,
// in this simple case infos are not used
shapes.save_infos(infos_have_templ, prefix + "case0/circle_info.yaml", false);
shapes.save_infos(infos_have_templ, prefix + "case0/circle_info.yaml");
std::cout << "train end" << std::endl << std::endl;

}else if(mode=="test"){
Expand Down Expand Up @@ -254,7 +254,7 @@ void angle_test(){
shapes.angle_range = {0, 360};
shapes.angle_step = 1;
shapes.produce_infos();
std::vector<shape_based_matching::shapeInfo_producer::shape_and_info> infos_have_templ;
std::vector<shape_based_matching::shapeInfo_producer::Info> infos_have_templ;
string class_id = "test";
for(auto& info: shapes.infos){
imshow("train", info.src);
Expand Down Expand Up @@ -331,6 +331,7 @@ void angle_test(){
Point(match.x+r-10, match.y-3), FONT_HERSHEY_PLAIN, 2, randColor);

cv::RotatedRect rotatedRectangle({x, y}, {2*r, 2*r}, -infos[match.template_id].angle);

cv::Point2f vertices[4];
rotatedRectangle.points(vertices);
for(int i=0; i<4; i++){
Expand Down Expand Up @@ -363,7 +364,7 @@ void noise_test(){
shapes.angle_range = {0, 360};
shapes.angle_step = 1;
shapes.produce_infos();
std::vector<shape_based_matching::shapeInfo_producer::shape_and_info> infos_have_templ;
std::vector<shape_based_matching::shapeInfo_producer::Info> infos_have_templ;
string class_id = "test";
for(auto& info: shapes.infos){
imshow("train", info.src);
Expand Down
1 change: 0 additions & 1 deletion test/case1/test_info.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
%YAML:1.0
---
save_src: 0
infos:
-
angle: 0.
Expand Down

0 comments on commit b3bee53

Please sign in to comment.