Skip to content

Instantly share code, notes, and snippets.

@kazoo04
Last active August 29, 2015 14:04
Show Gist options
  • Select an option

  • Save kazoo04/eea52e094afd3c78c09c to your computer and use it in GitHub Desktop.

Select an option

Save kazoo04/eea52e094afd3c78c09c to your computer and use it in GitHub Desktop.
Replace all pixels
cv::Mat src = cv::imread("example.jpg");
for(int y = 0; y < src.rows; ++y){
for(int x = 0; x < src.cols; ++x){
int index = y * src.step + x * src.elemSize();
int r = src.data[index + 2];
int g = src.data[index + 1];
int b = src.data[index + 0];
if(r == 255 && g == 255 && b == 255) {
src.data[index + 2] = 0;
src.data[index + 1] = 0;
src.data[index + 0] = 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment