Skip to content

Instantly share code, notes, and snippets.

@nkint
Last active January 1, 2016 12:29
Show Gist options
  • Save nkint/8144791 to your computer and use it in GitHub Desktop.
Save nkint/8144791 to your computer and use it in GitHub Desktop.
opencv: turn black pixels into alpha 0
displayDebug = ....
// turn black pixels into alpha 0
if(displayDebug.channels()==1)
cv::cvtColor(displayDebug, displayDebug, CV_GRAY2BGR);
cv::cvtColor(displayDebug, displayDebug, CV_BGR2BGRA);
for (cv::Mat4b::iterator it = displayDebug.begin<cv::Vec4b>(); it != displayDebug.end<cv::Vec4b>(); it++) {
if (*it == cv::Vec4b(0, 0, 0, 255)) {
*it = cv::Vec4b(0, 0, 0, 0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment