yuv = yuv.reshape((384, -1)) print(yuv.shape) tmp = yuv[:256, :] 这是python代码,可以转换为c++代码吗
时间: 2024-05-04 12:19:17 浏览: 72
将Python转换为C或C ++
可以,以下是对应的C++代码:
```cpp
#include <iostream>
#include <vector>
int main() {
std::vector<std::vector<int>> yuv(384, std::vector<int>(/*列数,待填写*/));
// 从 yuv 中读入数据
int cols = yuv[0].size(); // 列数
std::cout << "[";
for (int i = 0; i < 384; ++i) {
std::cout << "[";
for (int j = 0; j < cols; ++j) {
std::cout << yuv[i][j];
if (j != cols - 1) {
std::cout << ", ";
}
}
std::cout << "]";
if (i != 383) {
std::cout << ", ";
}
}
std::cout << "]" << std::endl;
std::vector<std::vector<int>> tmp(256, std::vector<int>(cols));
for (int i = 0; i < 256; ++i) {
for (int j = 0; j < cols; ++j) {
tmp[i][j] = yuv[i][j];
}
}
std::cout << "[";
for (int i = 0; i < 256; ++i) {
std::cout << "[";
for (int j = 0; j < cols; ++j) {
std::cout << tmp[i][j];
if (j != cols - 1) {
std::cout << ", ";
}
}
std::cout << "]";
if (i != 255) {
std::cout << ", ";
}
}
std::cout << "]" << std::endl;
return 0;
}
```
其中,`yuv` 是一个 2D 的 `std::vector`,`yuv[i][j]` 表示第 `i` 行第 `j` 列的值;`tmp` 同理,表示从 `yuv` 中取出前 256 行的数据。
阅读全文