opencv - ValueError:无法将大小为 230400 的数组重塑为形状 (1,153600)
问题描述
我正在尝试一个自动驾驶项目。我想通过 Jetson Nano 的相机接收框架来标记框架。但是,发生了与标题相同的错误。
temp_array = roi.reshape(1, int(height / 2) * width).astype(np.float32)
ValueError: cannot reshape array of size 230400 into shape (1,153600)
你能看看我的代码吗?
import socket
import numpy as np
import cv2
import pygame
HOST = '127.0.0.1'
PORT = 9999
def recvall(sock, count):
buf = b''
while count:
newbuf = sock.recv(count)
if not newbuf: return None
buf += newbuf
count -= len(newbuf)
return buf
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect((HOST, PORT))
while True:
length = recvall(client_socket, 16)
stringData = recvall(client_socket, int(length))
data = np.frombuffer(stringData, dtype='uint8')
decimg = cv2.imdecode(data, cv2. )
print(type(decimg)) # class numpy.ndarray
print(decimg.shape) # 480,640,3
height, width,_ = decimg.shape
roi = decimg[120:240, :] #120,640,3
print(roi.shape)
cv2.imshow('Client', decimg)
cv2.imshow('roi',roi)
temp_array = roi.reshape(1, int(height / 2) * width).astype(np.float32)
# print(temp_array)
key = cv2.waitKey(1)
if key == 27:
break```
解决方案
问题在于数组大小。您要将 230400 的数组重新整形为 (1, 153600)。我能知道你到底想做什么吗?
推荐阅读
- javascript - 遍历复杂的 DOM 并抓取值
- c# - 升级后运行 .NET Core 应用程序时出现 Http 错误
- r - R简单的dplyr解决方案进行过滤
- python - 如何从 kivy textinput 访问所选文本的开始和结束索引
- ios - 一个关于 iOS 自动布局与表格视图和自定大小表格视图单元格的谜团
- algorithm - 如何插入半排序列表?
- .net - 如何在给定日期的一周内获得工作日?
- rest - Acumatica - 通过 REST 进行通用查询
- python - 如何正确使用具有多个回归目标的形状决策图和力图?
- glob - {} 和 +() 之间的 glob 模式差异