[英]opencv::cuda GpuMat CV_8UC1 to CV_32FC1 convertion black image
I am converting opencv-python operations to c++ opencv::cuda for better performance but I have a problem about CV_8UC1 to CV_32FC1 convertion.我正在将 opencv-python 操作转换为 c++ opencv::cuda 以获得更好的性能,但我有关于 CV_8UC1 到 CV_32FC1 的转换的问题。
Python Code I want to convert:我要转换的 Python 代码:
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
img_float = np.float32(img_gray)
img_log = cv2.log(img_float)
print(img_log[100,100]) //Prints 5.325 floating value
cv2.imwrite("log_py.jpg", img_log) // shows log transformed image
C++ Code : C++ 代码:
cv::Mat src_host = cv::imread("crack2.jpg");
cv::Mat dst;
cv::cuda::GpuMat dst, src, log, gray_gpu;
src.upload(src_host);
cv::cuda::cvtColor(src, gray_gpu, cv::COLOR_BGR2GRAY);
gray_gpu.convertTo(gray_gpu, CV_32FC1);
cv::cuda::log(gray_gpu, log);
log.download(dst);
std::cout << "float : " << (float)(dst.at<float>(100,100)) << std::endl; //Prints 0 integer value
std::cout << "int : " << (int)(dst.at<uchar>(100,100)) << std::endl; //prints 128 integer value
cv::imwrite("log_cpp.jpg", dst); //shows black image
If I don't convert to CV_32FC1 it applies log transformation but images won't be same.如果我不转换为 CV_32FC1,它会应用对数转换,但图像不会相同。 I need to apply this log operation to floating value.我需要将此日志操作应用于浮动值。 What should I do?我该怎么办? , ( @zindarod ) , (@zindarod)
In-place operations do not seem to be working for opencv::cuda::GpuMat::convertTo
function.就地操作似乎不适用于opencv::cuda::GpuMat::convertTo
函数。
See these posts:看到这些帖子:
https://github.com/opencv/opencv/issues/13092 https://github.com/opencv/opencv/issues/13092
https://answers.opencv.org/question/97672/converting-gpumat-32fc1-8uc1/?answer=97690#post-id-97690 https://answers.opencv.org/question/97672/converting-gpumat-32fc1-8uc1/?answer=97690#post-id-97690
As a workaround, you can declare a new temporary variable and perform the operation on that variable:作为一种解决方法,您可以声明一个新的临时变量并对该变量执行操作:
cv::cuda::GpuMat gray_gpu_temp;
cv::cuda::cvtColor(src, gray_gpu_temp, cv::COLOR_BGR2GRAY);
gray_gpu_temp.convertTo(gray_gpu, CV_32FC1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.