Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions include/image_processing.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
#include <string>

#include "opencv2/core/core.hpp"
#include <opencv2/imgproc/imgproc.hpp>

using namespace std;
using namespace cv;

class ImageProcessor {
public:
Expand All @@ -15,4 +19,16 @@ class ImageProcessor {
const int kernelSize) = 0;
virtual cv::Mat Pixelize(const cv::Mat &src, const cv::Rect &roi,
const int kDivs) = 0;
};

class ImageProcessorImpl : public ImageProcessor {
public:
virtual cv::Mat CvtColor(const cv::Mat &src, const cv::Rect &roi);
virtual cv::Mat Filter(const cv::Mat &src, const cv::Rect &roi,
const int size);
virtual cv::Mat DetectEdges(const cv::Mat &src, const cv::Rect &roi,
const int filter_size, const int low_threshold,
const int ratio, const int kernel_size);
virtual cv::Mat Pixelize(const cv::Mat &src, const cv::Rect &roi,
const int divs);
};
14 changes: 14 additions & 0 deletions include/tracking.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,24 @@
#include <string>

#include "opencv2/core/core.hpp"
#include "opencv2/imgproc/imgproc.hpp"
#include "opencv2/video/video.hpp"
#include "opencv2/imgproc/imgproc.hpp"

class Tracker {
public:
static std::shared_ptr<Tracker> CreateTracker(const std::string &name);
virtual bool Init(const cv::Mat &frame, const cv::Rect &roi) = 0;
virtual cv::Rect Track(const cv::Mat &frame) = 0;
};


class MedianFlowTracker : public Tracker {
public:
virtual bool Init(const cv::Mat &frame, const cv::Rect &roi);
virtual cv::Rect Track(const cv::Mat &frame);

protected:
cv::Rect position_;
cv::Mat frame_;
};
179 changes: 179 additions & 0 deletions samples/imgproc_demo.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,179 @@
#include <iostream>
#include <string>

#include "opencv2/core.hpp"
#include "opencv2/highgui.hpp"
#include <opencv2/imgproc/imgproc.hpp>
#include <image_processing.hpp>

using namespace std;
using namespace cv;

const char* kAbout =
"This is an empty application that can be treated as a template for your "
"own doing-something-cool applications.";

const char* kOptions =
"{ @image | | image to process }"
"{ v video | | video to process }"
"{ gray | | convert ROI to gray scale}"
"{ h ? help usage | | print help message }";


struct MouseCallbackState {
bool is_selection_started;
bool is_selection_finished;
Point point_first;
Point point_second;
ImageProcessorImpl processor;
Mat img;
Rect roi;
bool grayOk;
string kSrcWindowName;
};

struct ProgState {
MouseCallbackState mouseState;
bool GrayOk;
};

void OnMouse(int event, int x, int y, int flags, void* params )
{

//state.
MouseCallbackState* state = (MouseCallbackState*)params;
if (event == EVENT_LBUTTONDOWN)
{
state->is_selection_started = true;
state->is_selection_finished = false;
state->point_first.x = x;
state->point_first.y = y;
}


if (event == EVENT_LBUTTONUP)
{
state->is_selection_started = false;
state->is_selection_finished = true;
state->point_second.x = x;
state->point_second.y = y;

state->img = state->processor.CvtColor(state->img, Rect (state->point_second, state->point_first));
imshow(state->kSrcWindowName, state->img);
}
else if (event == EVENT_RBUTTONDOWN)
{
//cout << "Right button of the mouse is clicked - position (" << x << ", " << y << ")" << endl;
}
else if (event == EVENT_MBUTTONDOWN)
{
//cout << "Middle button of the mouse is clicked - position (" << x << ", " << y << ")" << endl;
}
else if (event == EVENT_MOUSEMOVE)
{
if (state->is_selection_finished == false)
{
state->point_second.x = x;
state->point_second.y = y;
}

}
}


void DstImgCallback(int event, int x, int y, int flags, void* params)
{

//state.
MouseCallbackState* state = (MouseCallbackState*)params;
if (event == EVENT_LBUTTONDOWN)
{
state->is_selection_started = true;
state->is_selection_finished = false;
state->point_first.x = x;
state->point_first.y = y;
}

}


int main(int argc, const char** argv) {
// Parse command line arguments.
CommandLineParser parser(argc, argv, kOptions);
parser.about(kAbout);

// If help option is given, print help message and exit.
if (parser.get<bool>("help")) {
parser.printMessage();
return 0;
}

// Do something cool.
cout << "This is empty template sample." << endl;

// Read image.
Mat img = imread(parser.get<string>(0));
if (img.empty()) {
cout << "Failed to open image file '" + parser.get<string>(0) + "'."
<< endl;
return 0;
}



const string kSrcWindowName = "Source image";

const int kWaitKeyDelay = 1;
namedWindow(kSrcWindowName, WINDOW_NORMAL);
resizeWindow(kSrcWindowName, 640, 480);
ImageProcessorImpl processor;
MouseCallbackState state;
state.img = img;
state.processor = processor;
state.kSrcWindowName = kSrcWindowName;
setMouseCallback(kSrcWindowName, OnMouse, &state);
imshow(kSrcWindowName, img);
bool grayOk = false;
const int threshold = parser.get<int>("gray");
try {
grayOk = true;

}

catch (const std::exception& ex) {
cout << ex.what() << endl;
return 0;
}
state.grayOk = grayOk;

imshow(kSrcWindowName, state.img);
/*
const string kDstWindowName = "Destination image";
namedWindow(kDstWindowName, WINDOW_NORMAL);
resizeWindow(kDstWindowName, 640, 480);
setMouseCallback(kDstWindowName, DstImgCallback, &state);

if (grayOk) {

}*/


//waitKey(kWaitKeyDelay);
waitKey(0);

//Create a window
//namedWindow("My Window", 1);

//set the callback function for any mouse event
//setMouseCallback("My Window", CallBackFunc, NULL);

//show the image
//imshow("My Window", img);

// Wait until user press some key
//waitKey(0);

return 0;
}


30 changes: 15 additions & 15 deletions samples/template_demo.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,27 @@ using namespace std;
using namespace cv;

const char* kAbout =
"This is an empty application that can be treated as a template for your "
"own doing-something-cool applications.";
"This is an empty application that can be treated as a template for your "
"own doing-something-cool applications.";

const char* kOptions =
"{ v video | | video to process }"
"{ h ? help usage | | print help message }";
"{ v video | | video to process }"
"{ h ? help usage | | print help message }";


int main(int argc, const char** argv) {
// Parse command line arguments.
CommandLineParser parser(argc, argv, kOptions);
parser.about(kAbout);
// Parse command line arguments.
CommandLineParser parser(argc, argv, kOptions);
parser.about(kAbout);

// If help option is given, print help message and exit.
if (parser.get<bool>("help")) {
parser.printMessage();
return 0;
}
// If help option is given, print help message and exit.
if (parser.get<bool>("help")) {
parser.printMessage();
return 0;
}

// Do something cool.
cout << "This is empty template sample." << endl;
// Do something cool.
cout << "This is empty template sample." << endl;

return 0;
return 0;
}
Loading