将奇异的纹理转换为OpenCV图像

我正在尝试将我的猕猴桃纹理转换为图像格式,以便可以使用opencv(cv2)处理它。我尝试使用read()和cv2.imread()读取纹理,但均无效。我还考虑将ubyte纹理转换为字符串,但无济于事。

我可以使用cv2处理的

奇凡相机纹理->格式

类似

MyVariable = someid.texture
#do something to format of MyVariable so that it is an 'image'
Newvar = MyVariable.read()
#cv2 processing...

编辑:

好,所以我使用RGB阵列格式的texture.pixel从纹理中获取了数据。然后,我用

newvalue = np.frombuffer(camera.texture.pixels,np.uint8) 

将数据转换为numpy字符串。从那里很容易使用

将其重新显示在图像小部件上
finalstage = newvalue.tostring()
texture1 = Texture.create(size=variables.size,colorfmt='rgba')
texture1.blit_buffer(finalstage,colorfmt='rgba',bufferfmt='ubyte')
image.texture = texture1

我的问题是,现在我想使用Opencv在脸上绘制矩形,然后更新图像纹理。我有工作代码来绘制矩形,但是我首先需要使用

将RGB数据转换为灰色
gray = cv2.cvtColor(newvalue,cv2.COLOR_RGBA2GRAY)

这样做会返回我的新错误:

11-08 17:22:51.451 25259 25582 E cv::error(): OpenCV(4.0.1) Error: Unspecified error (> Invalid number of channels in input image:
11-08 17:22:51.451 25259 25582 E cv::error(): >     'VScn::contains(scn)'
11-08 17:22:51.451 25259 25582 E cv::error(): > where
11-08 17:22:51.451 25259 25582 E cv::error(): >     'scn' is 1
11-08 17:22:51.451 25259 25582 E cv::error(): ) in cv::CvtHelper<cv::Set<3,4,-1>,cv::Set<1,-1,cv::Set<0,2,5>,cv::SizePolicy::NONE>::CvtHelper(cv::InputArray,cv::OutputArray,int) [VScn = cv::Set<3,VDcn = cv::Set<1,VDepth = cv::Set<0,sizePolicy = cv::SizePolicy::NONE],file /home/.../color.hpp,line 259

如果我遗漏了一些东西,请告诉我

flypig1025 回答:将奇异的纹理转换为OpenCV图像

您必须重塑“ newvalue”

height,width = camera.texture.height,camera.texture.width

newvalue = np.frombuffer(camera.texture.pixels,np.uint8)
newvalue = newvalue.reshape(height,width,4)
gray = cv2.cvtColor(newvalue,cv2.COLOR_RGBA2GRAY)
本文链接:https://www.f2er.com/3143185.html

大家都在问