My first OpenCV Webcam Filter.
OpenCV is cool and makes it really easy to code stuff like this.
The Code:
static float alpha = 1.0f, tr = 0.1f, translation_variable = 0.01f;
void StrobeEffect(cv::Mat &frame) {
static unsigned int passIndex = 0;
for (int z = 0; z < frame.cols - 2; ++z) {
for (int i = 0; i < frame.rows - 2; ++i) {
cv::Vec3b &colors = frame.at<cv::Vec3b>(i, z);
switch (passIndex) {
case 0: {
colors[0] = colors[0] * (-alpha);
colors[1] = colors[1] * alpha;
colors[2] = colors[2] * alpha;
}
break;
case 1:
colors[0] = colors[0] * alpha;
colors[1] = colors[1] * (-alpha);
colors[2] = colors[2] * alpha;
break;
case 2:
colors[0] = colors[0] * alpha;
colors[1] = colors[1] * alpha;
colors[2] = colors[2] * (-alpha);
break;
case 3: {
cv::Vec3b &color1 = frame.at<cv::Vec3b>(i + 1, z);
cv::Vec3b &color2 = frame.at<cv::Vec3b>(i + 2, z);
colors[0] = colors[0] * alpha;
colors[1] = color1[1] * alpha;
colors[2] = color2[2] * alpha;
break;
}
}
if(isNegative == true) {
unsigned int &val = frame.at<unsigned int>(i, z);
val = -val;
}
}
}
++passIndex;
if(passIndex > 3) passIndex = 0;
static float max = 4.0f;
if(alpha < 0)
tr = translation_variable;
else if(alpha > max) {
tr = -translation_variable;
max += 3.0f;
if(max > 23) max = 4.0f;
}
alpha += tr;
}