c++ - 调整亮度和对比度 OpenCV C++
问题描述
我正在尝试调整 RGB 图像的亮度和对比度,但输出不是我所期望的。
该函数从 createTrackbar() 函数回调,其值从 0 到 100。
请检查下面的图片。我会很感激一些帮助。谢谢。
void brightness_callback(int brightness, void *userdata)
{
int height = image_input.rows, width = image_input.cols;
image_output = Mat::zeros(image_input.size(), image_input.type());
int widthStep = image_input.step;
int nChannels = 3;
uchar *pDataInput = (uchar *)image_input.data;
uchar *pDataOutput = (uchar *)image_output.data;
for (int x = 0; x < height; x++, pDataInput += widthStep, pDataOutput += widthStep) {
uchar *pRowInput = pDataInput;
uchar *pRowOutput = pDataOutput;
for (int y = 0; y < width; y++, pRowInput += nChannels, pRowOutput += nChannels) {
uchar B = pRowInput[0];
uchar G = pRowInput[1];
uchar R = pRowInput[2];
pRowOutput[0] = truncate((uchar)(B + brightness));
pRowOutput[1] = truncate((uchar)(G + brightness));
pRowOutput[2] = truncate((uchar)(R + brightness));
}
}
imshow(window_original, image_output);
}
uchar truncate(uchar value) {
if (value < 0) return 0;
else if (value > 255) return 255;
return value;
}
解决方案
推荐阅读
- git - PR 完成后,Jenkins 将禁用 GitHub 分支
- azure-devops - 使用 WinRM 的 IIS Web 应用程序部署未在用户名中转义 $
- sql - 在子查询 postgresql 中获取值
- lua - Lua string.match 在单个变量中捕获?
- python - 使用 Python Selenium 抓取动态网站
- recursion - BST中序递归:找到大于K的第一个节点
- reactjs - 尝试访问嵌套对象时,useContext 返回未定义
- c# - IEnumerable 和 OrderBy 的奇怪之处
- node.js - TypeError:无法读取未定义的属性“执行”
- sql-server - SQL Server 差异备份是否需要事务日志记录?