23#include <opencv2/imgproc/imgproc.hpp>
41 Effect::Morpho, Effect_Values, ParamCateg);
122 public jevois::Parameter<effect>
145 inimg.
require(
"input", w,
h, V4L2_PIX_FMT_YUYV);
152 outimg = outframe.get();
162 cv::Mat dst; std::string settings;
163 if (itsFilter) settings = itsFilter->process(src, dst);
164 else dst = cv::Mat(
h, w, CV_8UC3, cv::Scalar(0,0,0));
172 std::string
const & fpscpu = timer.
stop();
177 std::vector<std::string> svec =
jevois::split(settings,
"\n");
178 for (
size_t i = 0; i < svec.size(); ++i)
194 static int left = -1, right = -1;
197 unsigned short winw, winh;
201 int x = 0, y = 0;
unsigned short iw = 0, ih = 0;
204 helper.
itext(
"JeVois-Pro Color Filtering");
209 cv::Mat src = inframe.getCvRGBp();
210 int const sw = src.cols;
int const sh = src.rows;
214 cv::Mat dst; std::string settings;
215 if (itsFilter) settings = itsFilter->process(src, dst);
216 else dst = cv::Mat(sh, sw, CV_8UC3, cv::Scalar(0,0,0));
221 ImU32
const col = IM_COL32(128,255,255,255);
223 static bool dragleft =
false, dragright =
false;
226 if (jevois::frameNum() == 0) { left = sw / 4; right = 3 * sw / 4; }
229 if (left > right - siz) {
if (dragright) left = right - siz;
else right = left + siz; }
230 left = std::max(siz, std::min(sw - siz * 2, left));
231 right = std::max(left + siz, std::min(sw - siz, right));
235 cv::Mat ovl; cv::cvtColor(dst, ovl, cv::COLOR_RGB2RGBA);
236 ovl(cv::Rect(0, 0, left, sh)) = 0;
237 ovl(cv::Rect(right, 0, sw-right, sh)) = 0;
238 int ox = 0, oy = 0;
unsigned short ow = 0, oh = 0;
239 helper.
drawImage(
"filtered", ovl,
true, ox, oy, ow, oh,
false,
true );
241 helper.
drawLine(left, 0, left, sh, col);
242 helper.
drawRect(left-siz, (sh-siz)/2, left, (sh+siz)/2, col);
243 helper.
drawLine(right, 0, right, sh, col);
244 helper.
drawRect(right, (sh-siz)/2, right+siz, (sh+siz)/2, col);
247 ImVec2
const ip = helper.
d2i(ImGui::GetMousePos());
249 if (ImGui::IsMouseClicked(0))
252 if (ip.x > left-siz && ip.x < left && ip.y > (sh-siz)/2 && ip.y < (sh+siz)/2) dragleft =
true;
253 if (ip.x > right && ip.x < right+siz && ip.y > (sh-siz)/2 && ip.y < (sh+siz)/2) dragright =
true;
256 if (ImGui::IsMouseDragging(0))
258 if (dragleft) left = ip.x + 0.5F * siz;
259 if (dragright) right = ip.x - 0.5F * siz;
263 if (ImGui::IsMouseReleased(0))
270 std::string
const & fpscpu = timer.
stop();
271 helper.
itext(
"JeVois image filter: " + effect::strget());
272 std::vector<std::string> svec =
jevois::split(settings,
"\n");
273 for (std::string
const & s : svec) helper.
itext(s);
274 helper.
iinfo(inframe, fpscpu, winw, winh);
290 case Effect::NoEffect:
break;
291 case Effect::Blur: itsFilter = addSubComponent<BlurFilter>(
"filter");
break;
292 case Effect::Median: itsFilter = addSubComponent<MedianFilter>(
"filter");
break;
293 case Effect::Morpho: itsFilter = addSubComponent<MorphologyFilter>(
"filter");
break;
294 case Effect::Laplacian: itsFilter = addSubComponent<LaplacianFilter>(
"filter");
break;
295 case Effect::Bilateral: itsFilter = addSubComponent<BilateralFilter>(
"filter");
break;
300 std::shared_ptr<Filter> itsFilter;
JEVOIS_REGISTER_MODULE(ArUcoBlob)
Image filtering using OpenCV.
void onParamChange(effect const &, Effect const &val) override
Parameter callback: set the selected filter algo.
virtual void process(jevois::InputFrame &&inframe, jevois::OutputFrame &&outframe) override
Processing function with video output to USB.
JEVOIS_DEFINE_ENUM_CLASS(Effect,(NoEffect)(Blur)(Median)(Morpho)(Laplacian)(Bilateral))
Enum.
virtual ~ColorFiltering()
Virtual destructor for safe inheritance.
JEVOIS_DECLARE_PARAMETER_WITH_CALLBACK(effect, Effect, "Image processing effect to apply", Effect::Morpho, Effect_Values, ParamCateg)
Parameter.
virtual void process(jevois::InputFrame &&inframe, jevois::GUIhelper &helper) override
Processing function with zero-copy and GUI on JeVois-Pro.
friend friend class Module
void removeSubComponent(std::shared_ptr< Comp > &component)
void drawInputFrame(char const *name, InputFrame const &frame, int &x, int &y, unsigned short &w, unsigned short &h, bool noalias=false, bool casync=false)
bool startFrame(unsigned short &w, unsigned short &h)
void drawRect(float x1, float y1, float x2, float y2, ImU32 col=IM_COL32(128, 255, 128, 255), bool filled=true)
void iinfo(jevois::InputFrame const &inframe, std::string const &fpscpu, unsigned short winw=0, unsigned short winh=0)
void drawLine(float x1, float y1, float x2, float y2, ImU32 col=IM_COL32(128, 255, 128, 255))
void itext(char const *txt, ImU32 const &col=IM_COL32_BLACK_TRANS, int line=-1)
ImVec2 d2i(ImVec2 p, char const *name=nullptr)
void drawImage(char const *name, RawImage const &img, int &x, int &y, unsigned short &w, unsigned short &h, bool noalias=false, bool isoverlay=false)
void require(char const *info, unsigned int w, unsigned int h, unsigned int f) const
std::string const & stop(double *seconds)
void paste(RawImage const &src, RawImage &dest, int dx, int dy)
void writeText(RawImage &img, std::string const &txt, int x, int y, unsigned int col, Font font=Font6x10)
cv::Mat convertToCvBGR(RawImage const &src)
void pasteBGRtoYUYV(cv::Mat const &src, RawImage &dst, int dx, int dy)
std::future< std::invoke_result_t< std::decay_t< Function >, std::decay_t< Args >... > > async(Function &&f, Args &&... args)
std::vector< std::string > split(std::string const &input, std::string const ®ex="\\s+")
unsigned short constexpr White