c++ 打印 torch tensor
c++ 打印 torch tensor_jacke121的专栏-CSDN博客_libtorch打印tensor
c++ char数组和char*
如果数组长,有多少复制多少,如果数组短,则数组填满为止
打印数组:
vector<Mat> bgr;
cv::split(imgResized, bgr);
bgr[0].convertTo(bgr[0], CV_32F, 1.f / 127.5f, -1.f);
bgr[1].convertTo(bgr[1], CV_32F, 1.f / 127.5f, -1.f);
bgr[2].convertTo(bgr[2], CV_32F, 1.f / 127.5f, -1.f);
for (int a = 0; a < 20; a++) {
cout << ((float*)(bgr[0].data))[a] << " ";
}
cout << endl;
cout不需要强转类型,理论上这个也可以:
vector<Mat> bgr;
cv::split(imgResized, bgr);
bgr[0].convertTo(bgr[0], CV_32F, 1.f / 127.5f, -1.f);
bgr[1].convertTo(bgr[1], CV_32F, 1.f / 127.5f, -1.f);
bgr[2].convertTo(bgr[2], CV_32F, 1.f / 127.5f, -1.f);
for (int a = 0; a < 20; a++) {
cout << (float*)(bgr[0].data)[a] << " ";
}
cout << endl;
char arr[2] = { 0 };
int i;
for (i = 0; i < sizeof(arr); i++) {
printf("%c\n", arr[i]);
}
// 创建一个指针,并指向静态区存放的一个字符串“ABC”
char* tmp = "ABCDEF";
// 利用字符串拷贝函数进行拷贝
//strcpy(arr, tmp);
// 例如内存拷贝函数进行拷贝
memcpy(arr,tmp, sizeof(arr));
//int i;
for (i = 0; i < sizeof(arr); i++) {
printf("%c\n", arr[i]);
}