首页 > 解决方案 > 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```

标签: opencvtcpvideo-streaminglabeling

解决方案


问题在于数组大小。您要将 230400 的数组重新整形为 (1, 153600)。我能知道你到底想做什么吗?


推荐阅读