python-3.x - Python3 cv2: 错误: (-215) scn == 3 || 函数 cv::cvtColor 中的 scn == 4 仅在脚本文件中
问题描述
此错误error: (-215) scn == 3 || scn == 4 in function cv::cvtColor
仅在我的脚本中,但如果我在 IPython shell 中运行代码,一切正常。该代码用于减少运行的 DQN(Deeq-Q-network)的尺寸,openai-gym
我不知道为什么这不在我的脚本中而是在我的 shell 中。
如果出现错误,我添加了一条评论。如果需要,可以添加完整的代码。
部分代码:
def preprocess(self,inp):
inp=cv2.resize(inp,(84, 110))
inp=cv2.cvtColor(inp, cv2.COLOR_BGR2GRAY)
inp=inp[26:110,:]
ret,obs=cv2.threshold(inp,1,255,cv2.THRESH_BINARY)
return np.reshape(obs,(84,84,1))
def Q_Learning(self,modell_path="Your path here"):
observation=self.env.reset()
for i in range(self.itertime):
observation=self.preprocess(observation)#!Error appers here!
if np.random.rand()<=self.random_move_prop:
action=np.random.randint(low=0,high=self.env.action_space.n)
else:
action=self.model.predict(observation)
action=np.argmax(action)
new_observation, reward, done, info=self.env.step(action)
new_observation=self.preprocess(new_observation)
self.storage.append([observation,action,reward,new_observation,done])
observation=new_observation
if done:
self.env.reset()
解决方案
推荐阅读
- python - 使用python从代码中的其他部分开始和停止while循环
- apache-flink - sinkfunction的概念及其在Flink中的丰富sinkfunction的实现
- java - 如何修改json响应?
- apache-nifi - 在全局变量中组合表达式函数
- android - NFC:蓝牙 LE OOB 配对 + Android 应用启动
- c++ - 为什么 DBDATE 在 OLE DB 中有一个有符号整数类型?
- linux - Kubernetes 无法识别通配符*
- css - Odoo V11 - 如何使用 CSS 类设置看板样式,并将字段值作为类名的一部分
- javascript - 什么提示确认表格重新提交?
- facebook-graph-api - 如何使用 facebook API 以二进制形式上传视频?