SOL9 Sample: ImageFlipping
|
1 Screenshot
2 Source code
/*
* ImageFlipping.cpp
* Copyright (c) 2015 Antillia.com TOSHIYUKI ARAI. ALL RIGHTS RESERVED.
*/
//2017/03/30
#define _CONSOLE_
#include <sol/ModuleFileName.h>
#include <sol/opencv/OpenCVApplicationView.h>
#include <sol/opencv/OpenCVNamedWindow.h>
namespace SOL {
class MainView :public OpenCVApplicationView {
private:
////////////////////////////////////////////////////////////////////////////////////////
//Inner class starts.
class SimpleView :public OpenCVNamedWindow {
private:
cv::Mat image;
void display()
{
show(image);
}
public:
SimpleView(View* parent, const char* name, Args& args)
:OpenCVNamedWindow(parent, name, args)
{
}
~SimpleView()
{
}
void setFlippedImage(cv::Mat& mat, int flip)
{
try {
cv::Mat flipped;
cv::flip(mat, flipped, flip);
image = flipped;
invalidateAll();
update();
} catch (SOL::Exception ex) {
caught(ex);
}
}
};
//Inner class ends.
////////////////////////////////////////////////////////////////////////////////////////
static const int VIEW_COUNT = 3;
SmartPtr<SimpleView> view[VIEW_COUNT];
void resize(int w, int h)
{
if (view[0]) {
for (int i = 0; i<VIEW_COUNT; i++) {
view[i] -> reshape( w*i/VIEW_COUNT, 0, w/VIEW_COUNT, h);
}
}
}
void confirm(Action& action)
{
int rc = MessageBox(NULL, "Are you sure to close this window?", "Confirmation",
MB_OKCANCEL|MB_ICONEXCLAMATION);
if (rc == IDOK) {
exit(action);
}
}
public:
MainView(OpenCVApplication& applet, const char* name, Args& args)
:OpenCVApplicationView(applet, name, args)
{
try {
Args ar;
cv::Mat mat = imread("..\\images\\cat.jpg", CV_LOAD_IMAGE_COLOR);
int flip = -1;
for (int i = 0; i<VIEW_COUNT; i++) {
char name[128];
sprintf_s(name, CountOf(name), "cvwindow.%d", i);
view[i] = new SimpleView(this, name, ar);
view[i]->setFlippedImage(mat, flip++);
}
addCallback(XmNmenuCallback, IDM_EXIT, this,
(Callback)&MainView::confirm, NULL);
} catch (Exception& ex) {
caught(ex);
}
}
~MainView()
{
}
};
}
//
void main(int argc, char** argv)
{
try {
ModuleFileName module(argv[0]);
const char* name = module.getAppName();
OpenCVApplication applet(name, argc, argv);
Args args;
args.set(XmNwidth, 900);
args.set(XmNheight, 300);
MainView view(applet, name, args);
view.realize();
applet.run();
} catch (SOL::Exception& ex) {
caught(ex);
}
}
Last modified: 2 Dec. 2017
Copyright (c) 2017 Antillia.com ALL RIGHTS RESERVED.