gpt4 book ai didi

c - 从左到右、从上到下翻转图像

转载 作者:行者123 更新时间:2023-11-30 17:26:33 25 4
gpt4 key购买 nike

我做了两个函数,一个函数从左到右翻转图像,另一个函数从上到下翻转图像。但由于某种原因,当我加载图像时,图像没有发生任何变化。

这是从左向右翻转的代码。

void flip_horizontal( uint8_t array[], 
unsigned int cols,
unsigned int rows )
{
unsigned int left = 0;
unsigned int right = cols;
for(int r = 0; r < rows; r++)
{
while(left != right && right > left)
{
int temp = array[r * cols+ left];
array[(r * cols) + left] = array[(r * cols) + cols - right];
array[(r * cols) + cols - right] = temp;
right++;
left++;
}
}
}

这是从上到下翻转的代码。

void flip_vertical( uint8_t array[], 
unsigned int cols,
unsigned int rows )
{
unsigned int top = 0;
unsigned int bottom = rows;
for(int r = 0; r < cols; r++)
{
while(top != bottom && bottom > top)
{
int temp = array[r * rows+ top];
array[(r * rows) + top] = array[(r * rows) + rows - bottom];
array[(r * rows) + rows - bottom] = temp;
bottom++;
top++;
}
}
}

最佳答案

尝试将它们移动到 for 循环中:

unsigned int left = 0;
unsigned int right = cols;

unsigned int top = 0;
unsigned int bottom = rows;

否则,您只会翻转第一行/列。

您的索引方式还存在一些其他问题,但我不会破坏修复这些问题的乐趣:-)

关于c - 从左到右、从上到下翻转图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26732094/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com