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
3 changes: 2 additions & 1 deletion include/retro_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,12 @@ class RetroFilter
RetroFilter(const Parameters& params);
virtual ~RetroFilter() {};

void applyToVideo(const cv::Mat& frame, cv::Mat& retroFrame);
void applyToVideo(const cv::Mat& frame, cv::Mat& retroFrame, int flag);

private:
Parameters params_;
cv::RNG rng_;
cv::Mat a,b,c;

float hsvScale_;
float hsvOffset_;
Expand Down
14 changes: 12 additions & 2 deletions sample/retro_sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ const char* params =

int main(int argc, const char** argv)
{
int flag = 49;
// Parse command line arguments
CommandLineParser parser(argc, argv, params);

Expand Down Expand Up @@ -100,14 +101,23 @@ int main(int argc, const char** argv)
{
Mat retroFrame;
TS(filter);
filter.applyToVideo(frame, retroFrame);
filter.applyToVideo(frame, retroFrame, flag);
TE(filter);

imshow("Original Movie", frame);
imshow("Retro Movie", retroFrame);
char c = (char) waitKey(1);
if( c == 27 ) // Esc
switch (c)
{
case 49: { flag = 49; break; };
case 50: { flag = 50; break; };
case 51: { flag = 51; break; };
}

if (c == 27)
{
break;
}

capture >> frame;
if(frame.empty()) break;
Expand Down
61 changes: 40 additions & 21 deletions src/retro_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ RetroFilter::RetroFilter(const Parameters& params) : rng_(time(0))
hsvOffset_ = 20;
}

void RetroFilter::applyToVideo(const Mat& frame, Mat& retroFrame)
void RetroFilter::applyToVideo(const Mat& frame, Mat& retroFrame, int flag)
{
int col, row;
Mat luminance;
Expand All @@ -46,14 +46,9 @@ void RetroFilter::applyToVideo(const Mat& frame, Mat& retroFrame)
int x = rng_.uniform(0, params_.scratches.cols - luminance.cols);
int y = rng_.uniform(0, params_.scratches.rows - luminance.rows);

for (row = 0; row < luminance.size().height; row += 1)
{
for (col = 0; col < luminance.size().width; col += 1)
{
uchar pix_color = params_.scratches.at<uchar>(row + y, col + x) ? (int)scratchColor.at<uchar>(row, col) : luminance.at<uchar>(row, col);
luminance.at<uchar>(row, col) = pix_color;
}
}
Rect rect(x, y, luminance.cols, luminance.rows);
Mat qqq = params_.scratches(rect);
luminance.setTo(meanColor * 2.0, qqq);

// Add fuzzy border
Mat borderColor(params_.frameSize, CV_32FC1, Scalar::all(meanColor[0] * 1.5));
Expand All @@ -62,21 +57,45 @@ void RetroFilter::applyToVideo(const Mat& frame, Mat& retroFrame)

// Apply sepia-effect
retroFrame.create(luminance.size(), CV_8UC3);
Mat hsv_pixel(1, 1, CV_8UC3);
Mat rgb_pixel(1, 1, CV_8UC3);
for (col = 0; col < luminance.size().width; col += 1)

switch (flag)
{
for (row = 0; row < luminance.size().height; row += 1)
case 49:
{
hsv_pixel.ptr()[2] = cv::saturate_cast<uchar>(luminance.at<uchar>(row, col) * hsvScale_ + hsvOffset_);
hsv_pixel.ptr()[0] = 19;
hsv_pixel.ptr()[1] = 78;
Mat a,b,c;
a.create( luminance.size(),CV_8UC1);
a.setTo(19);
b.create( luminance.size(),CV_8UC1);
b.setTo(78);
c.create( luminance.size(),CV_8UC1);
c = luminance * hsvScale_ + hsvOffset_;

cvtColor(hsv_pixel, rgb_pixel, CV_HSV2RGB);

retroFrame.at<Vec3b>(row, col)[0] = rgb_pixel.ptr()[2];
retroFrame.at<Vec3b>(row, col)[1] = rgb_pixel.ptr()[1];
retroFrame.at<Vec3b>(row, col)[2] = rgb_pixel.ptr()[0];
std::vector<Mat> mat;
mat.push_back(a);
mat.push_back(b);
mat.push_back(c);
cv::merge(mat,retroFrame);
cv::cvtColor(retroFrame,retroFrame,COLOR_HSV2BGR);
break;
}
case 50:
{
std::vector<Mat> mat;
mat.push_back(luminance);
mat.push_back(luminance);
mat.push_back(luminance);
cv::merge(mat,retroFrame);
break;
}
case 51:
{
std::vector<Mat> mat;
mat.push_back(luminance);
mat.push_back(luminance);
mat.push_back(luminance);
cv::merge(mat,retroFrame);
cv::cvtColor(retroFrame,retroFrame,COLOR_HSV2BGR);
break;
}
}
}