我正在尝试将我的Python代码翻译成C++ (为了提高速度)。
我的代码通过套接字接收图像并显示它。
Python代码:
self._img = cv2.imdecode(np.fromstring(self._SocketData, np.uint8), 1)
if not self._img is None:
self._img = cv2.resize(self._img, (1280, 720))
cv2.imshow("1", self._img)
cv2.waitKey(1)
不幸的是,我在C++中遇到了"np.fromstring“的问题。
如何实现这一点?
我试着这样做:
while (ignored_error != boost::asio::error::eof) {
boost::array<uchar, 10000> RECV_DATA;
size_t ImageSize = image_recver.read_some(
boost::asio::buffer(RECV_DATA), ignored_error);
vector<uchar> Img (ImageSize);
for (int i = 0; i < ImageSize; i++) {
Img[i] = RECV_DATA[i];
}
Mat img(1280, 720, CV_64F, Img.data());
imshow("1", img);
waitKey(1);
}
但这不起作用(我认为这是由于"cv2.imdecode“和”np.fromstring“造成的)。
请帮帮我
P.S通常,我的主要问题完全在np.fromstring中,因为从套接字im获得一个字符串,而不是一些字节或整数,并且我应该将一个字符串转换为像素数组(分别为0-255)。
转载请注明出处:http://www.ydsst.com/article/20230526/1430212.html