mirror of
https://github.com/SrIzan10/makesweet-api.git
synced 2026-05-01 10:55:14 +00:00
allow loading geometry from json; sample slightly more cleanly
This commit is contained in:
@@ -11,4 +11,7 @@ FIND_PACKAGE(YARP)
|
||||
INCLUDE_DIRECTORIES(${YARP_INCLUDE_DIRS})
|
||||
LINK_LIBRARIES(${YARP_LIBRARIES})
|
||||
|
||||
find_package(PkgConfig REQUIRED)
|
||||
pkg_check_modules(JSONCPP jsoncpp)
|
||||
|
||||
ADD_SUBDIRECTORY(src)
|
||||
|
||||
@@ -29,6 +29,10 @@ RUN \
|
||||
apt-get update; \
|
||||
apt-get install -y libopencv-videoio-dev
|
||||
|
||||
RUN \
|
||||
apt-get update; \
|
||||
apt-get install -y libjsoncpp-dev
|
||||
|
||||
COPY . /makesweet/
|
||||
|
||||
RUN \
|
||||
|
||||
@@ -18,7 +18,8 @@ ELSE()
|
||||
SET(PROTO_HDRS)
|
||||
ENDIF()
|
||||
|
||||
ADD_LIBRARY(msmap msmap.h msmap.c)
|
||||
ADD_LIBRARY(msmap STATIC msmap.h msmap.c)
|
||||
include_directories(${JSONCPP_INCLUDE_DIRS})
|
||||
|
||||
ADD_EXECUTABLE(reanimator reanimator.cpp Prop.h Prop.cpp Pixer.h
|
||||
Mapping.h Mapping.cpp Repository.h Repository.cpp Render.h Render.cpp
|
||||
@@ -42,3 +43,5 @@ endif()
|
||||
if (USE_DETAIL)
|
||||
TARGET_LINK_LIBRARIES(reanimator ${PROTOBUF_LIBRARIES})
|
||||
endif()
|
||||
|
||||
target_link_libraries(reanimator ${JSONCPP_LIBRARIES})
|
||||
|
||||
50
src/Pixer.h
50
src/Pixer.h
@@ -43,9 +43,21 @@ public:
|
||||
p.a = a/v;
|
||||
return p;
|
||||
}
|
||||
|
||||
void preblend() {
|
||||
r *= a;
|
||||
g *= a;
|
||||
b *= a;
|
||||
}
|
||||
|
||||
void postblend(double sc) {
|
||||
r /= sc;
|
||||
g /= sc;
|
||||
b /= sc;
|
||||
}
|
||||
};
|
||||
|
||||
inline Pixer sampleLinear(const yarp::sig::ImageOf<yarp::sig::PixelBgra>& src,
|
||||
inline Pixer sampleWeakly(const yarp::sig::ImageOf<yarp::sig::PixelBgra>& src,
|
||||
double x, double y) {
|
||||
const yarp::sig::PixelBgra& p = src.safePixel(x,y);
|
||||
Pixer v;
|
||||
@@ -56,4 +68,40 @@ inline Pixer sampleLinear(const yarp::sig::ImageOf<yarp::sig::PixelBgra>& src,
|
||||
return v;
|
||||
}
|
||||
|
||||
inline Pixer sampleLinear(const yarp::sig::ImageOf<yarp::sig::PixelBgra>& src,
|
||||
double x, double y) {
|
||||
int xx = (int)x;
|
||||
int yy = (int)y;
|
||||
float fx = x - xx;
|
||||
float fy = y - yy;
|
||||
const yarp::sig::PixelBgra& poo = src.safePixel(x,y);
|
||||
const yarp::sig::PixelBgra& poy = src.safePixel(x,y+1);
|
||||
const yarp::sig::PixelBgra& pxo = src.safePixel(x+1,y);
|
||||
const yarp::sig::PixelBgra& pxy = src.safePixel(x+1,y+1);
|
||||
Pixer v;
|
||||
double aa = (1-fx)*(1-fy)*poo.a + fx*(1-fy)*pxo.a + (1-fx)*fy*poy.a + fx*fy*pxy.a;
|
||||
if (aa < 0.0001) aa = 0.0001;
|
||||
v.r =
|
||||
((1-fx)*(1-fy)*poo.r*poo.a +
|
||||
fx*(1-fy)*pxo.r*pxo.a +
|
||||
(1-fx)*fy*poy.r*poy.a +
|
||||
fx*fy*pxy.r*pxy.a)/aa;
|
||||
v.g =
|
||||
((1-fx)*(1-fy)*poo.g*poo.a +
|
||||
fx*(1-fy)*pxo.g*pxo.a +
|
||||
(1-fx)*fy*poy.g*poy.a +
|
||||
fx*fy*pxy.g*pxy.a)/aa;
|
||||
v.b =
|
||||
((1-fx)*(1-fy)*poo.b*poo.a +
|
||||
fx*(1-fy)*pxo.b*pxo.a +
|
||||
(1-fx)*fy*poy.b*poy.a +
|
||||
fx*fy*pxy.b*pxy.a)/aa;
|
||||
v.a =
|
||||
(1-fx)*(1-fy)*poo.a +
|
||||
fx*(1-fy)*pxo.a +
|
||||
(1-fx)*fy*poy.a +
|
||||
fx*fy*pxy.a;
|
||||
return v;
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@@ -250,16 +250,28 @@ void Render::add(const Input& in) {
|
||||
Pixer m4b = sampleLinear(in.get(),xx-(xxa+xxb)/2.0,yy-(yya+yyb)/2.0);
|
||||
Pixer m5b = sampleLinear(in.get(),xx-(xxa-xxb)/2.0,yy-(yya-yyb)/2.0);
|
||||
|
||||
mo.preblend();
|
||||
m2.preblend();
|
||||
m3.preblend();
|
||||
m4.preblend();
|
||||
m5.preblend();
|
||||
m2b.preblend();
|
||||
m3b.preblend();
|
||||
m4b.preblend();
|
||||
m5b.preblend();
|
||||
double sc = (mo.a*4.0 + (m2.a+m3.a+m4.a+m5.a)*2.0 + (m2b.a+m3b.a+m4b.a+m5b.a))/16.0;
|
||||
mo = (mo*4.0 + (m2+m3+m4+m5)*2.0 + (m2b+m3b+m4b+m5b))/16.0;
|
||||
if (sc > 0.0001) {
|
||||
mo.postblend(sc);
|
||||
} else {
|
||||
mo.r = mo.g = mo.b = mo.a = 0.0;
|
||||
}
|
||||
|
||||
m.r = mo.r;
|
||||
m.g = mo.g;
|
||||
m.b = mo.b;
|
||||
m.a = mo.a;
|
||||
//} else {
|
||||
//m = in.get().safePixel((int)xx,(int)yy);
|
||||
//}
|
||||
|
||||
//const PixelBgra& m = in.get().safePixel((int)xx,(int)yy);
|
||||
PixelBgra result;
|
||||
if (d && act>25) {
|
||||
result.r = darkPixel.r + ((lightPixel.r-darkPixel.r)*m.r)/255;
|
||||
|
||||
@@ -16,6 +16,10 @@
|
||||
#include "VidAnim.h"
|
||||
#include "Dbg.h"
|
||||
|
||||
#include <json/json.h>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
using namespace std;
|
||||
using namespace yarp::os;
|
||||
using namespace yarp::sig;
|
||||
@@ -33,9 +37,10 @@ int main(int argc, char *argv[]) {
|
||||
|
||||
Repository repo;
|
||||
|
||||
if (!options.check("zip")) {
|
||||
if (!options.check("zip") && !options.check("json")) {
|
||||
fprintf(stderr, "reanimator --zip foo.zip --in layer1.png layer2.png\n");
|
||||
fprintf(stderr, "reanimator --zip foo.zip --in layer1.png layer2.png +layer2_more.png\n");
|
||||
fprintf(stderr, "reanimator --json setup.json\n");
|
||||
fprintf(stderr, "reanimator ... --w 200 --h 150\n");
|
||||
fprintf(stderr, "reanimator ... --first 2\n");
|
||||
fprintf(stderr, "reanimator ... --last 4\n");
|
||||
@@ -50,10 +55,36 @@ int main(int argc, char *argv[]) {
|
||||
exit(1);
|
||||
}
|
||||
|
||||
repo.load(options.find("zip").asString().c_str());
|
||||
|
||||
Inputs ins;
|
||||
|
||||
if (options.check("json")) {
|
||||
std::ifstream file(options.find("json").asString().c_str());
|
||||
Json::Value root;
|
||||
file >> root;
|
||||
std::cout << root;
|
||||
Json::Value inputs = root["inputs"];
|
||||
for (int i=0; i<inputs.size(); i++) {
|
||||
std::cout << i << std::endl;
|
||||
Json::Value input = inputs[i];
|
||||
std::string filename = input["filename"].asString();
|
||||
std::cout << filename << std::endl;
|
||||
Input& in = ins.add();
|
||||
in.load(filename.c_str());
|
||||
in.layer = input["layer"].asInt();
|
||||
in.xs = input["xs"].asDouble();
|
||||
in.ys = input["ys"].asDouble();
|
||||
in.xo = input["xo"].asDouble();
|
||||
in.yo = input["yo"].asDouble();
|
||||
in.in_scale = input["in_scale"].asInt();
|
||||
in.in_x0 = input["in_x0"].asDouble();
|
||||
in.in_y0 = input["in_y0"].asDouble();
|
||||
in.xa = input["in_xa"].asDouble();
|
||||
in.ya = input["in_ya"].asDouble();
|
||||
}
|
||||
}
|
||||
|
||||
repo.load(options.find("zip").asString().c_str());
|
||||
|
||||
Bottle& lst = options.findGroup("in");
|
||||
int layer = 1;
|
||||
for (int i=1; i<lst.size(); i++) {
|
||||
|
||||
Reference in New Issue
Block a user