cann版本是6.0.1RC 使用AclLite的ReadJpeg从路径读取图片加载到device在进行reszie成功,代码如下:
成功结果如下:这里的4805是怎么计算得到的? DeviceImage width: 157
DeviceImage height: 39
DeviceImage size: 4805
DeviceImage format: 4222924
yuvImage_ width: 158
yuvImage_ height: 40
yuvImage_ size: 13824
yuvImage_ format: 1
resizedImage width: 320
resizedImage height: 48
resizedImage size: 23040
resizedImage format: 1
使用CopyDataToDevice从cv::Mat读取到device在resize失败。代码如下:
失败结果如下: imageDevice_ width: 157
imageDevice_ height: 39
imageDevice_ size: 9184
imageDevice_ format: 1
yuvImage_ width: 158
yuvImage_ height: 40
yuvImage_ size: 13824
yuvImage_ format: 1
ret resize: 0
resizedImage width: 0
resizedImage height: 0
resizedImage size: 0
resizedImage format: -1953859032
由以下两个问题: 1、使用readJpeg读取图片的宽是157,高是39,为什么size是4805? 2、使用CopyDataToDevice从cv::Mat读取到device在resize为什么失败了?二者在reszie之前都转化为YUV,而且维度,大小都是一样的。
cann版本是6.0.1RC 使用AclLite的ReadJpeg从路径读取图片加载到device在进行reszie成功,代码如下:
Result OcrRecognizer::ProcessInput(std::string img_path, int tar_w, int tar_h) { ImageData image; AclLiteError ret = ReadJpeg(image, img_path); if (ret == FAILED) { ACLLITE_LOG_ERROR("ReadJpeg failed, errorCode is %d", ret); return FAILED; } std::cout << "ReadJpeg width: " << image.width << std::endl; std::cout << "ReadJpeg height: " << image.height << std::endl; std::cout << "ReadJpeg size: " << image.size << std::endl; std::cout << "ReadJpeg format: " << image.format << std::endl; // 检查ImageData是否成功读取 if (!image.data || image.width == 0 || image.height == 0) { std::cout << "Invalid image data for image: " << img_path << std::endl; return FAILED; } // 输出image.data.get()的地址和值 std::cout << "image.data.get(): " << static_cast<void*>(image.data.get()) << std::endl; std::cout << "Image dimensions: width = " << image.width << ", height = " << image.height << std::endl; std::cout << "First 10 bytes of image data: "; for (int i = 0; i < std::min(10U, image.size); ++i) { std::cout << static_cast<int>(image.data.get()[i]) << " "; } std::cout << std::endl; // 将图像从主机复制到设备 ImageData DeviceImage; // AclLiteError ret = CopyImageToDevice(DeviceImage, resizedImageData, runMode_, MEMORY_DVPP); ret = CopyImageToDevice(DeviceImage, image, runMode_, MEMORY_DVPP); if (ret == FAILED) { std::cerr << "Failed to copy image to device for: " << img_path << std::endl; ACLLITE_LOG_ERROR("CopyImageToDevice failed, errorCode is %d", ret); return FAILED; } std::cout << "DeviceImage width: " << DeviceImage.width << std::endl; std::cout << "DeviceImage height: " << DeviceImage.height << std::endl; std::cout << "DeviceImage size: " << DeviceImage.size << std::endl; std::cout << "DeviceImage format: " << DeviceImage.format << std::endl; // 转化为yuv图片 ImageData yuvImage_; ret = imageProcess_.JpegD(yuvImage_, DeviceImage); if (ret == FAILED) { ACLLITE_LOG_ERROR("Convert jpeg to yuv failed, errorCode is %d", ret); return FAILED; } std::cout << "yuvImage_ width: " << yuvImage_.width << std::endl; std::cout << "yuvImage_ height: " << yuvImage_.height << std::endl; std::cout << "yuvImage_ size: " << yuvImage_.size << std::endl; std::cout << "yuvImage_ format: " << yuvImage_.format << std::endl; ret = imageProcess_.Resize(resizedImage_, yuvImage_, modelWidth_, modelHeight_); if (ret == FAILED) { ACLLITE_LOG_ERROR("Resize image failed, errorCode is %d", ret); return FAILED; } std::cout << "resizedImage width: " << resizedImage_.width << std::endl; std::cout << "resizedImage height: " << resizedImage_.height << std::endl; std::cout << "resizedImage size: " << resizedImage_.size << std::endl; std::cout << "resizedImage format: " << resizedImage_.format << std::endl; std::cout << "Successfully processed image: " << img_path << std::endl; return SUCCESS; }成功结果如下:这里的4805是怎么计算得到的? DeviceImage width: 157
DeviceImage height: 39
DeviceImage size: 4805
DeviceImage format: 4222924
yuvImage_ width: 158
yuvImage_ height: 40
yuvImage_ size: 13824
yuvImage_ format: 1
resizedImage width: 320
resizedImage height: 48
resizedImage size: 23040
resizedImage format: 1
使用CopyDataToDevice从cv::Mat读取到device在resize失败。代码如下:
std::vector<std::pair<std::string, float>> OcrRecognizer::recGetResult(const std::vector<cv::Mat> &imgsPreBatch, const std::vector<int> &indices) { std::vector<std::pair<std::string, float>> rec_res(indices.size(), {"", 0.0f}); std::cout << "In Rec Get Result: " << std::endl; std::cout << "imgsPreBatch.size(): " << imgsPreBatch.size() << std::endl; std::cout << "indices.size(): " << indices.size() << std::endl; for (int batch = 0; batch < imgsPreBatch.size(); batch++) { std::cout << "Processing batch: " << batch << " of " << imgsPreBatch.size() << std::endl; cv::Mat imageBatch = imgsPreBatch[batch]; uint32_t imageInfoSize = YUV420SP_SIZE(imageBatch.cols, imageBatch.rows); void* imageInfoBuf = CopyDataToDevice(imageBatch.data, imageInfoSize, runMode_, MEMORY_DVPP); if (imageInfoBuf == nullptr) { std::cerr << "Failed to copy data to device." << std::endl; continue; } ImageData imageDevice_ ; imageDevice_.data = SHARED_PTR_DVPP_BUF(imageInfoBuf); imageDevice_.size = imageInfoSize; imageDevice_.width = imageBatch.cols; imageDevice_.height = imageBatch.rows; imageDevice_.format = PIXEL_FORMAT_YUV_SEMIPLANAR_420; imageDevice_.alignWidth = (imageBatch.cols % 2 == 1) ? imageBatch.cols + 1 : imageBatch.cols; imageDevice_.alignHeight = (imageBatch.rows % 2 == 1) ? imageBatch.rows + 1 : imageBatch.rows; std::cout << "imageDevice_ width: " << imageDevice_.width << std::endl; std::cout << "imageDevice_ height: " << imageDevice_.height << std::endl; std::cout << "imageDevice_ size: " << imageDevice_.size << std::endl; std::cout << "imageDevice_ format: " << imageDevice_.format << std::endl; // 转化为yuv图片 ImageData yuvImage_; AclLiteError ret = imageProcess_.JpegD(yuvImage_, imageDevice_); if (ret == FAILED) { ACLLITE_LOG_ERROR("Convert jpeg to yuv failed, errorCode is %d", ret); return rec_res; } std::cout << "yuvImage_ width: " << yuvImage_.width << std::endl; std::cout << "yuvImage_ height: " << yuvImage_.height << std::endl; std::cout << "yuvImage_ size: " << yuvImage_.size << std::endl; std::cout << "yuvImage_ format: " << yuvImage_.format << std::endl; ret = imageProcess_.Resize(resizedImageRec_, yuvImage_, 320, 48); std::cout << "ret resize: " << ret << std::endl; if (ret == FAILED) { ACLLITE_LOG_ERROR("Resize image failed, errorCode is %d", ret); return rec_res; } std::cout << "resizedImage width: " << resizedImage_.width << std::endl; std::cout << "resizedImage height: " << resizedImage_.height << std::endl; std::cout << "resizedImage size: " << resizedImage_.size << std::endl; std::cout << "resizedImage format: " << resizedImage_.format << std::endl; ret = model_.CreateInput(static_cast<void*>(resizedImageRec_.data.get()), resizedImageRec_.size); if (ret == FAILED) { ACLLITE_LOG_ERROR("CreateInput failed, errorCode is %d", ret); return rec_res; // 返回空结果 } std::vector<InferenceOutput> inferOutputs; ret = model_.Execute(inferOutputs); if (ret != ACL_SUCCESS || inferOutputs.empty() || inferOutputs[0].data == nullptr) { ACLLITE_LOG_ERROR("Model execution failed or outputs are empty, errorCode is %d", ret); return rec_res; // 返回空结果 } } }失败结果如下: imageDevice_ width: 157
imageDevice_ height: 39
imageDevice_ size: 9184
imageDevice_ format: 1
yuvImage_ width: 158
yuvImage_ height: 40
yuvImage_ size: 13824
yuvImage_ format: 1
ret resize: 0
resizedImage width: 0
resizedImage height: 0
resizedImage size: 0
resizedImage format: -1953859032
由以下两个问题: 1、使用readJpeg读取图片的宽是157,高是39,为什么size是4805? 2、使用CopyDataToDevice从cv::Mat读取到device在resize为什么失败了?二者在reszie之前都转化为YUV,而且维度,大小都是一样的。