Citra awal
Citra hasil invert
Nah, pada program OpenCV kali ini, kita akan melakukan proses invert citra. Istilahnya citra awal kita ubah menjadi citra negative. Berikut
adalah source code nya:
void InvertColour( Mat& input_image, Mat& output_image )
{
CV_Assert( input_image.type() == CV_8UC3 );
output_image = input_image.clone();
for (int row=0; row < input_image.rows; row++)
for (int col=0; col < input_image.cols; col++)
for (int channel=0; channel < input_image.channels(); channel++)
output_image.at<Vec3b>(row,col)[channel] = 255 - input_image.at<Vec3b>(row,col)[channel];
}
int main(int argc, char **argv)
{
Mat image = imread("img/test.png", CV_LOAD_IMAGE_COLOR);
namedWindow("display window");
Mat out;
imshow("display window", image);
InvertColour(image, out);
imshow("display window", out);
waitKey(0);// wait for a keystroke in the window
return 0;
}
0 komentar:
Post a Comment