26 #include <linux/videodev2.h>
28 #include <opencv2/imgproc/imgproc.hpp>
96 itsFilter = addSubComponent<FilterGPU>(
"gpu");
97 itsSaliency = addSubComponent<Saliency>(
"saliency");
98 itsKF = addSubComponent<Kalman2D>(
"kalman");
101 itsSaliency->centermin::set(1);
102 itsSaliency->smscale::set(3);
111 itsFilter->setProgram(
"shaders/simplevertshader.glsl",
"shaders/combofragshader.glsl");
112 itsFilter->setProgramParam2f(
"offset", -1.0
F, -1.0
F);
113 itsFilter->setProgramParam2f(
"scale", 2.0
F, 2.0
F);
121 inimg.
require(
"input",
w,
h, V4L2_PIX_FMT_YUYV);
128 std::unique_lock<std::mutex> lck(itsOutMtx);
133 itsSaliency->process(inimg,
true);
136 int mx, my;
intg32 msal; itsSaliency->getSaliencyMax(mx, my, msal);
139 int const smlev = itsSaliency->smscale::get();
140 int const smadj = smlev > 0 ? (1 << (smlev-1)) : 0;
141 unsigned int const dmx = (mx << smlev) + smadj;
142 unsigned int const dmy = (my << smlev) + smadj;
143 unsigned int const mapw = itsSaliency->salmap.dims.w, maph = itsSaliency->salmap.dims.h;
145 unsigned int const gistw =
w - 6 * mapw;
149 itsKF->set(dmx, dmy,
w,
h);
150 float kfxraw, kfyraw; itsKF->get(kfxraw, kfyraw, 1.0
F);
156 std::lock_guard<std::mutex> _(itsOutMtx);
159 unsigned int offset = 0;
169 unsigned char * d = outimg.
pixelsw<
unsigned char>() + 4*
w*
h + 6*mapw;
170 for (
unsigned int i = 0; i < maph; ++i) memcpy(d + i*
w, itsSaliency->gist + i*gistw, gistw);
177 itsSaliency->waitUntilDoneWithInput();
181 cv::Mat gpuout(
h,
w, CV_8UC4);
182 itsFilter->process(grayimg, gpuout);
185 outimg = outframe.get();
187 outimg.
require(
"output",
w,
h * 4 + (
h >> itsSaliency->smscale::get()), V4L2_PIX_FMT_GREY);
203 unsigned int bitshift)
206 unsigned int const ow = outimg.
width, oh = outimg.
height;
208 if (dy + fh > oh)
LFATAL(
"Map would extend past output image bottom");
209 if (fw + dx > ow)
LFATAL(
"Map would extend past output image width");
211 unsigned int const stride = ow - fw;
213 intg32 * s = fmap.
pixels;
unsigned char * d = outimg.
pixelsw<
unsigned char>() + dx + dy * ow;
215 for (
unsigned int j = 0; j < fh; ++j)
217 for (
unsigned int i = 0; i < fw; ++i)
219 intg32 v = (*s++) >> bitshift;
if (v > 255) v = 255;
220 *d++ = (
unsigned char)(v);
230 std::shared_ptr<FilterGPU> itsFilter;
231 std::shared_ptr<Saliency> itsSaliency;
232 std::shared_ptr<Kalman2D> itsKF;
233 std::mutex itsOutMtx;