GlreadPixels如何获得像素值

发布于 2025-01-23 03:04:50 字数 638 浏览 2 评论 0 原文

我使用此功能返回这样的值。我希望获得每个像素的RGB值,即0到255,而不是0到1。我该怎么办

data = glReadPixels(0,0, w, h, GL_RGB,GL_UNSIGNED_BYTE)
print(data)

<

\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad

a href =“ https://i.sstatic.net/jiio6.png” rel =“ nofollow noreferrer“> ”

I use this function to return such a value. I hope to get the RGB value of each pixel, which is 0 to 255, not 0 to 1. What should I do

data = glReadPixels(0,0, w, h, GL_RGB,GL_UNSIGNED_BYTE)
print(data)

output

\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad\xd1\x9e\xad

enter image description here

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

遥远的绿洲 2025-01-30 03:04:50

使用将字符串转换为字节阵列:

import numpy
data = glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE)
byte_array = numpy.frombuffer(data, dtype='uint8')
print(list(byte_array))

或使用

import ctypes
data = glReadPixels(0,0, w, h, GL_RGB,GL_UNSIGNED_BYTE)
byte_array = (ctypes.c_ubyte * (w * h * 3)).from_buffer_copy(data)
print(list(byte_array))

Use numpy.frombuffer to convert the string to a byte array:

import numpy
data = glReadPixels(0, 0, w, h, GL_RGB, GL_UNSIGNED_BYTE)
byte_array = numpy.frombuffer(data, dtype='uint8')
print(list(byte_array))

Or use ctypes.from_buffer_copy

import ctypes
data = glReadPixels(0,0, w, h, GL_RGB,GL_UNSIGNED_BYTE)
byte_array = (ctypes.c_ubyte * (w * h * 3)).from_buffer_copy(data)
print(list(byte_array))
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文