aboutsummaryrefslogtreecommitdiffstats
path: root/meowpp.test/src
diff options
context:
space:
mode:
Diffstat (limited to 'meowpp.test/src')
-rw-r--r--meowpp.test/src/autostitch_RansacCheck.cpp2
-rw-r--r--meowpp.test/src/features.cpp204
-rw-r--r--meowpp.test/src/features_Harris.cpp85
-rw-r--r--meowpp.test/src/rot_bundle.cpp6
4 files changed, 292 insertions, 5 deletions
diff --git a/meowpp.test/src/autostitch_RansacCheck.cpp b/meowpp.test/src/autostitch_RansacCheck.cpp
index e728958..1516d1a 100644
--- a/meowpp.test/src/autostitch_RansacCheck.cpp
+++ b/meowpp.test/src/autostitch_RansacCheck.cpp
@@ -77,7 +77,7 @@ Vector<double> MyRansacCheck::vCalc(std::vector<FeaturePointIndexPair> const& __
for (size_t j = i + 1; j < 8u; j++) {
sum += x(j) * m(i, j);
}
- x.entry(i, (m(i, 8) - sum) / m(i, i));
+ x.scalar(i, (m(i, 8) - sum) / m(i, i));
}
return x;
}
diff --git a/meowpp.test/src/features.cpp b/meowpp.test/src/features.cpp
index 382dffa..9547216 100644
--- a/meowpp.test/src/features.cpp
+++ b/meowpp.test/src/features.cpp
@@ -1,11 +1,33 @@
#include <cstdio>
+#include "features__.h"
+
#include "meowpp/Usage.h"
+#include "meowpp/colors/RGB_Space.h"
+#include "meowpp/geo/Vectors.h"
+#include "meowpp/gra/Bitmap.h"
+#include "meowpp/oo/ObjBase.h"
+#include "meowpp/oo/ObjSelector.h"
+
+#include <opencv/cv.h>
+#include <opencv/highgui.h>
+
+extern "C"{
+#include <sys/types.h>
+#include <dirent.h>
+}
+
+#include <vector>
+#include <algorithm>
+#include <string>
using namespace meow;
Usage usg("features");
+std::vector<std::string> names;
+std::vector<std::vector<FeaturePoint<double, double> > > fps;
+
int setup(int argc, char** argv) {
usg.optionAdd("h" , "Display this help document");
usg.optionAdd("help", "Display this help document");
@@ -17,12 +39,192 @@ int setup(int argc, char** argv) {
false);
usg.optionAdd("o",
"Output images with denoting feature points",
+ "filename",
+ "",
+ false);
+ usg.optionAdd("f",
+ "Output text file name",
+ "filename",
+ "<<input image name>>.txt",
+ false);
+ usg.optionAdd("d",
+ "Specify which feature detect algorithm to use",
+ "name",
+ "",
+ true);
+ std::vector<std::string> algo_list(ObjSelector<kFPSD_ID>::names());
+ for (size_t i = 0, I = algo_list.size(); i < I; ++i) {
+ FeaturePointsDetectors const* f;
+ f = (FeaturePointsDetectors const*)ObjSelector<kFPSD_ID>::get(algo_list[i]);
+ usg.optionValueAcceptAdd("d", algo_list[i], f->description());
+ usg.import(f->usage());
+ }
+ std::string err;
+ bool ret = usg.arguments(argc, argv, &err);
+ if (usg.hasOptionSetup("h") || usg.hasOptionSetup("help")) {
+ fprintf(stderr, "%s\n", usg.usage().c_str());
+ return 0;
+ }
+ if (ret == false) {
+ fprintf(stderr, "%s\n", err.c_str());
+ return -1;
+ }
+ return 1;
+}
+
+int getName() {
+ if (usg.hasOptionSetup("i") == false) {
+ names = usg.procArgs();
+ }
+ else {
+ std::string base = usg.optionValue("i", 0);
+ if (base.length() == 0 || base[base.length() - 1] != '/') {
+ base += "/";
+ }
+ DIR* dir = opendir(base.c_str());
+ if (!dir) {
+ fprintf(stderr, "can't open dir '%s'\n", base.c_str());
+ return -1;
+ }
+ for (dirent* ent; (ent = readdir(dir)) != NULL; ) {
+ if (!cstringEndWith(ent->d_name, 4, ".jpeg", ".jpg", ".JPG", ".JPEG")) {
+ continue;
+ }
+ names.push_back(base + std::string(ent->d_name));
+ }
+ }
+ return 1;
+}
+
+Bitmap<RGBf_Space> readOne(std::string name) {
+ Bitmap<RGBf_Space> ret;
+ messagePrintf(1, "Loading image...");
+ cv::Mat img = cv::imread(name, CV_LOAD_IMAGE_COLOR);
+ if (img.data) {
+ size_t height = img.size().height;
+ size_t width = img.size().width ;
+ ret.size(height, width, RGBf_Space(0));
+ for (size_t y = 0; y < height; ++y) {
+ for (size_t x = 0; x < width; ++x) {
+ Vector3D<int> v;
+ for (size_t i = 0; i < 3; ++i)
+ v.scalar(i, img.at<cv::Vec3b>(y, x)[2 - i]);
+ RGBf_Space p;
+ colorTransformate(RGBi_Space(v), &p);
+ ret.pixel(y, x, p);
+ }
+ }
+ }
+ messagePrintf(-1, (ret.size() > 0 ? "ok" : "fail"));
+ return ret;
+}
+
+int features() {
+ std::string n(usg.optionValue("d", 0));
+ FeaturePointsDetectors* fpd((FeaturePointsDetectors*)
+ ObjSelector<kFPSD_ID>::create(n));
+ if (fpd->usage(usg) == false) {
+ fprintf(stderr, "\nArgument setup error for '%s'\n", n.c_str());
+ return -1;
+ }
+ for (size_t i = 0, I = names.size(); i < I; ++i) {
+ messagePrintf(1, "Finding feature points of '%s'", names[i].c_str());
+ Bitmap<RGBf_Space> bmp(readOne(names[i]));
+ if (bmp.size() == 0) {
+ messagePrintf(-1, "fail");
+ continue;
+ }
+ messagePrintf(0, "Height x Width = %lux%lu", bmp.height(), bmp.width());
+ fps.push_back(fpd->detect(bmp));
+ messagePrintf(-1, "ok");
+ }
+ delete fpd;
+ return 1;
+}
+
+int writeOne(FILE* f, size_t i) {
+ if (fprintf(f, "%d\n", (int)fps[i].size()) < 1) return -1;
+ for (size_t j = 0, J = fps[i].size(); j < J; ++j) {
+ if (fps[i][j].write(f, false, 0) == false) return -1;
+ }
+ return 1;
+}
+
+int writeText() {
+ for (size_t i = 0, I = fps.size(); i < I; ++i) {
+ std::string name2;
+ if (usg.hasOptionSetup("f")) { name2 = usg.optionValue("f", i); }
+ else { name2 = names[i] + ".txt"; }
+ messagePrintf(1, "Write text file to '%s'", name2.c_str());
+ FILE* f = fopen(name2.c_str(), "w");
+ if (f == NULL) {
+ messagePrintf(-1, "fail to open file!, ignore");
+ continue;
+ }
+ if (writeOne(f, i) < 0) {
+ messagePrintf(-1, "write fail");
+ fclose(f);
+ continue;
+ }
+ fclose(f);
+ messagePrintf(-1, "ok");
+ }
+ return 1;
+}
+
+int writeBmpOne(std::string name, Bitmap<RGBf_Space> const& bmp) {
+ size_t height = bmp.height();
+ size_t width = bmp.width ();
+ cv::Mat img(height, width, CV_8UC3);
+ for (size_t y = 0; y < height; y++) {
+ for (size_t x = 0; x < width; x++) {
+ RGBi_Space tmp;
+ colorTransformate(bmp.pixel(y, x), &tmp);
+ for (size_t i = 0; i < 3; ++i)
+ img.at<cv::Vec3b>(y, x)[i] = tmp.rgb(2 - i);
+ }
+ }
+ if (imwrite(name, img) == false) {
+ return -1;
+ }
+ return 1;
+}
+
+int writeBmp() {
+ if (usg.hasOptionSetup("o") == false)
+ return 1;
+ for (size_t i = 0, I = names.size(); i < I; ++i) {
+ std::string name2;
+ name2 = stringPrintf("%s%lu.jpg", usg.optionValue("o", 0).c_str(), i);
+ messagePrintf(1, "Write img file to '%s'", name2.c_str());
+ Bitmap<RGBf_Space> bmp(readOne(names[i]));
+ bool succ;
+ if ((succ = (bmp.size() > 0))) {
+ int wh = std::min(bmp.height(), bmp.width()) / 16;
+ for (size_t j = 0, J = fps[i].size(); j < J; ++j) {
+ int x0 = fps[i][j].position()(0);
+ int y0 = fps[i][j].position()(1);
+ for (int dx = -wh; dx <= wh; ++dx)
+ if (0 <= x0 + dx && x0 + dx < (int)bmp.width())
+ bmp.pixel(y0, x0 + dx, RGBf_Space(Vector3D<double>(1.0, 0.0, 0.0)));
+ for (int dy = -wh; dy <= wh; ++dy)
+ if (0 <= y0 + dy && y0 + dy < (int)bmp.height())
+ bmp.pixel(y0 + dy, x0, RGBf_Space(Vector3D<double>(1.0, 0.0, 0.0)));
+ }
+ succ = (writeBmpOne(name2, bmp) > 0);
+ }
+ messagePrintf(0, "ok");
+ }
return 1;
}
int main(int argc, char** argv) {
int ret;
- if ((ret = setup(argc, argv)) <= 0) return -1;
+ if ((ret = setup(argc, argv)) <= 0) return ret;
+ if ((ret = getName()) <= 0) return ret;
+ if ((ret = features()) <= 0) return ret;
+ if ((ret = writeText()) <= 0) return ret;
+ if ((ret = writeBmp()) <= 0) return ret;
return 0;
}
diff --git a/meowpp.test/src/features_Harris.cpp b/meowpp.test/src/features_Harris.cpp
new file mode 100644
index 0000000..f3c2c10
--- /dev/null
+++ b/meowpp.test/src/features_Harris.cpp
@@ -0,0 +1,85 @@
+#include "features__.h"
+
+#include "meowpp/oo/ObjBase.h"
+#include "meowpp/oo/ObjSelector.h"
+#include "meowpp/geo/Vectors.h"
+#include "meowpp/gra/FeaturePointsDetector_Harris.h"
+
+using namespace meow;
+
+class Harris: public FeaturePointsDetectors {
+ private:
+ FeaturePointsDetector_Harris<RGBf_Space> detector_;
+ public:
+ std::string description() const {
+ return "Harris-Corner-Detect";
+ }
+
+ Usage usage() const {
+ Usage ret;
+ ret.optionAdd("harris-k",
+ "Specify the constant K of 'R = detM - KtraceM'",
+ "<floating point>",
+ stringPrintf("%.10f", detector_.paramK()),
+ false);
+ ret.optionAdd("harris-r",
+ "Specify the threshold of R to determind whether is "
+ "featuer point or not",
+ "<floating point>",
+ stringPrintf("%.10f", detector_.paramR()),
+ false);
+ ret.optionAdd("harris-w",
+ "Specify the sigma of the gaussian blur",
+ "<floating point>",
+ stringPrintf("%.10f", detector_.paramW()),
+ false);
+ ret.optionAdd("harris-n",
+ "Specify the sigma of the gaussian blur to de-noise",
+ "<floating point>",
+ stringPrintf("%.10f", detector_.paramN()),
+ false);
+ ret.optionAdd("harris-g",
+ "Specify sigma of the gaussian blur to generate feature",
+ "<floating point>",
+ stringPrintf("%.10f", detector_.paramG()),
+ false);
+ ret.optionAdd("harris-l",
+ ".........",
+ "<floating point>",
+ stringPrintf("%.10f", detector_.paramL()),
+ false);
+ ret.optionAdd("harris-b",
+ "Description size",
+ "<number>",
+ stringPrintf("%lu", detector_.paramB()),
+ false);
+ return ret;
+ }
+
+ bool usage(meow::Usage const& usg) {
+ double K = atof(usg.optionValue("harris-k", 0).c_str());
+ double R = atof(usg.optionValue("harris-r", 0).c_str());
+ double W = atof(usg.optionValue("harris-w", 0).c_str());
+ double N = atof(usg.optionValue("harris-n", 0).c_str());
+ double L = atof(usg.optionValue("harris-l", 0).c_str());
+ double G = atof(usg.optionValue("harris-g", 0).c_str());
+ size_t B = atoi(usg.optionValue("harris-b", 0).c_str());
+ detector_.paramK(K);
+ detector_.paramR(R);
+ detector_.paramW(W);
+ detector_.paramN(N);
+ detector_.paramL(L);
+ detector_.paramG(G);
+ detector_.paramB(B);
+ return true;
+ }
+
+ FeaturePoints detect(Bitmap<RGBf_Space> const& bmp) {
+ return detector_.detect(bmp);
+ }
+
+ std::string type() const { return std::string("Harris"); }
+ ObjBase* create() const { return new Harris(); }
+};
+
+static meow::ObjSelector<kFPSD_ID> __(new Harris(), true);
diff --git a/meowpp.test/src/rot_bundle.cpp b/meowpp.test/src/rot_bundle.cpp
index d626e8e..38ffce8 100644
--- a/meowpp.test/src/rot_bundle.cpp
+++ b/meowpp.test/src/rot_bundle.cpp
@@ -122,8 +122,8 @@ bool read() {
fprintf(stderr, "format error!\n");
exit(-1);
}
- v.entry(0, x - center[i].x());
- v.entry(1, -(y - center[i].y()));
+ v.scalar(0, x - center[i].x());
+ v.scalar(1, -(y - center[i].y()));
fpsv[i].push_back(v);
fps_id[i].push_back(id_max++);
}
@@ -160,7 +160,7 @@ bool read() {
for (size_t j = 0, J = fps_id[i].size(); j < J; ++j) {
int id = st.root(fps_id[i][j]);
s += stringPrintf("%d ", id);
- eyes[i].cameraGet().fixedPoints2DGet().identityPointAdd(id, fpsv[i][j]);
+ eyes[i].cameraGet().fixedPoints2DGet().pointAdd(id, fpsv[i][j]);
}
messagePrintf(0, "%s", s.c_str());
}