diff --git a/sample/retro_sample.cpp b/sample/retro_sample.cpp index d4b031e..1b0019f 100644 --- a/sample/retro_sample.cpp +++ b/sample/retro_sample.cpp @@ -86,6 +86,7 @@ int main(int argc, const char** argv) Mat frame; capture >> frame; + capture >> frame; if (frame.empty()) { diff --git a/src/retro_filter.cpp b/src/retro_filter.cpp index f38b65a..58e9672 100644 --- a/src/retro_filter.cpp +++ b/src/retro_filter.cpp @@ -1,6 +1,8 @@ #include "retro_filter.hpp" #include "opencv2/imgproc/imgproc.hpp" +#include "opencv2\highgui\highgui.hpp" #include +#include using namespace std; using namespace cv; @@ -36,47 +38,39 @@ RetroFilter::RetroFilter(const Parameters& params) : rng_(time(0)) void RetroFilter::applyToVideo(const Mat& frame, Mat& retroFrame) { - int col, row; Mat luminance; cvtColor(frame, luminance, CV_BGR2GRAY); - // Add scratches - Scalar meanColor = mean(luminance.row(luminance.rows / 2)); - Mat scratchColor(params_.frameSize, CV_8UC1, meanColor * 2.0); 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(row + y, col + x) ? (int)scratchColor.at(row, col) : luminance.at(row, col); - luminance.at(row, col) = pix_color; - } - } + Scalar meanColor = mean(luminance.row(luminance.rows / 2)); + + Rect pos(x, y, luminance.cols, luminance.rows); + + luminance.setTo(meanColor * 2.0, params_.scratches(pos)); + - // Add fuzzy border + // Add fuzzy border Mat borderColor(params_.frameSize, CV_32FC1, Scalar::all(meanColor[0] * 1.5)); alphaBlend(borderColor, luminance, params_.fuzzyBorder); // 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) - { - for (row = 0; row < luminance.size().height; row += 1) - { - hsv_pixel.ptr()[2] = cv::saturate_cast(luminance.at(row, col) * hsvScale_ + hsvOffset_); - hsv_pixel.ptr()[0] = 19; - hsv_pixel.ptr()[1] = 78; - - cvtColor(hsv_pixel, rgb_pixel, CV_HSV2RGB); - - retroFrame.at(row, col)[0] = rgb_pixel.ptr()[2]; - retroFrame.at(row, col)[1] = rgb_pixel.ptr()[1]; - retroFrame.at(row, col)[2] = rgb_pixel.ptr()[0]; - } - } + Mat v = luminance * hsvScale_ + hsvOffset_; + Mat s(luminance.size(), CV_8UC1, Scalar(78, 0, 0)); + Mat h(luminance.size(), CV_8UC1, Scalar(19, 0, 0)); + + std::vector hsv; + hsv.push_back(h); + hsv.push_back(s); + hsv.push_back(v); + cv::merge(hsv, luminance); + + cvtColor(luminance, retroFrame, CV_HSV2BGR); + + + + } +/*https://docs.google.com/document/d/1R8-PY-nklomHmxXBJx_6Uitn0fjtcj1n_oxPIK7Gs3M/edit?pli=1#*/ \ No newline at end of file diff --git a/testdata/image.png b/testdata/image.png new file mode 100644 index 0000000..9959238 Binary files /dev/null and b/testdata/image.png differ