Skip to content
Open
Show file tree
Hide file tree
Changes from 5 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
2 changes: 0 additions & 2 deletions include/retro_filter.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,6 @@ class RetroFilter
Parameters params_;
cv::RNG rng_;

float hsvScale_;
float hsvOffset_;
};

#endif //__RETRO_FILTER_H__
47 changes: 27 additions & 20 deletions sample/retro_sample.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,43 +59,47 @@ int main(int argc, const char** argv)
return 1;

VideoCapture capture;
if (!video_file.empty())
{
capture.open(video_file);
if (!capture.isOpened())
{
if (!video_file.empty())
{
cout << "Error: failed to open video stream for: " << video_file << endl;
return 1;
capture.open(video_file);
if (!capture.isOpened())
{
cout << "Error: failed to open video stream for: " << video_file << endl;
return 1;
}
}
}
else if (use_camera)
{
capture.open(0);
if (!capture.isOpened())
else if (use_camera)
{
capture.open(0);
if (!capture.isOpened())
{
cout << "Error: failed to open video stream for camera #0" << endl;
return 1;
}
}
else
{
cout << "Error: failed to open video stream for camera #0" << endl;
cout << "Error: declare a source of images" << endl;
parser.printParams();
return 1;
}
}
else
{
cout << "Error: declare a source of images" << endl;
parser.printParams();
return 1;
}

Mat frame;
capture >> frame;

if (frame.empty())
while (frame.empty())
{
// empty video; lets consider this to be OK
return 0;
//return 0;
capture >> frame;
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Неправильный цикл. Будет работать бесконечно, если приходят пустые кадры.


params.frameSize = frame.size();
RetroFilter filter(params);

long sh=0;
for(;;)
{
Mat retroFrame;
Expand All @@ -111,6 +115,9 @@ int main(int argc, const char** argv)

capture >> frame;
if(frame.empty()) break;
if(sh>1000) break;
sh++;
std::cout<<sh<<"\n";
}

return 0;
Expand Down
29 changes: 17 additions & 12 deletions src/retro_filter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,6 @@ RetroFilter::RetroFilter(const Parameters& params) : rng_(time(0))
resize(params_.scratches, params_.scratches, params_.frameSize);
}

hsvScale_ = 1;
hsvOffset_ = 20;
}

void RetroFilter::applyToVideo(const Mat& frame, Mat& retroFrame)
Expand Down Expand Up @@ -62,21 +60,28 @@ 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);
Mat hsv_image(luminance.size().height, luminance.size().width, CV_8UC3);
Mat rgb_image(luminance.size().height, luminance.size().width, 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<uchar>(luminance.at<uchar>(row, col) * hsvScale_ + hsvOffset_);
hsv_pixel.ptr()[0] = 19;
hsv_pixel.ptr()[1] = 78;
hsv_image.ptr(row,col)[0] = 19;
hsv_image.ptr(row,col)[1] = 78;
hsv_image.ptr(row,col)[2] = cv::saturate_cast<uchar>(luminance.at<uchar>(row, col) + 20);
}
}

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно ускорить за счет использования функции merge (документация к функции)


cvtColor(hsv_pixel, rgb_pixel, CV_HSV2RGB);
cvtColor(hsv_image, rgb_image, 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];
for (col = 0; col < luminance.size().width; col += 1)
{
for (row = 0; row < luminance.size().height; row += 1)
{
retroFrame.at<Vec3b>(row, col)[0] = rgb_image.ptr(row,col)[2];
retroFrame.at<Vec3b>(row, col)[1] = rgb_image.ptr(row,col)[1];
retroFrame.at<Vec3b>(row, col)[2] = rgb_image.ptr(row,col)[0];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно ускорить за счет последовательного применения функций split (документация к функции) и merge.

}
}
}
}