简体   繁体   English

opencv::cuda GpuMat CV_8UC1 到 CV_32FC1 转换黑色图像

[英]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.

相关问题 类型断言失败。 类型 == CV_8UC1 || stype == CV_16SC1 || stype == CV_32SC1 || function 中的 stype == CV_32FC1 - type assertion failed. type == CV_8UC1 || stype == CV_16SC1 || stype == CV_32SC1 || stype == CV_32FC1 in function 如何在 Python 中将任何图像转换为 CV_32FC1 - How to convert any image to CV_32FC1 in Python OPENCV 4.04 &gt; THRESH_OTSU 模式:&gt; 'src_type == CV_8UC1 || src_type == CV_16UC1' &gt; 其中 &gt; 'src_type' 是 6 (CV_64FC1) - OPENCV 4.04 > THRESH_OTSU mode: > 'src_type == CV_8UC1 || src_type == CV_16UC1' > where > 'src_type' is 6 (CV_64FC1) 转换成灰度后仍然不能在 OpenCV 中使用 cv.equalizeHist()。 给出错误:(-215:断言失败)_src.type()== CV_8UC1 - Still after convertion into grayscale can not use cv.equalizeHist() in OpenCV. Gives error: (-215:Assertion failed) _src.type() == CV_8UC1 使用 cmap 在 opencv 中保存 16 位图像(cv::ColorMap 仅支持函数“operator()”中类型为 CV_8UC1 或 CV_8UC3 的源图像) - Saving 16-bit image in opencv with cmap (cv::ColorMap only supports source images of type CV_8UC1 or CV_8UC3 in function 'operator()') dct 中的断言失败(类型 == CV_32FC1 || 类型 == CV_64FC1) - Assertion failed (type == CV_32FC1 || type == CV_64FC1) in dct (215:Assertion failed) type == CV_32FC1 || 类型 == CV_32FC2 || 类型 == CV_64FC1 || 在函数 &#39;dft&#39; 中输入 == CV_64FC2 - (215:Assertion failed) type == CV_32FC1 || type == CV_32FC2 || type == CV_64FC1 || type == CV_64FC2 in function 'dft' OpenCV: 错误: (-215:Assertion failed) _src.type() == CV_8UC1 in function 'cv::equalizeHist' - OpenCV: error: (-215:Assertion failed) _src.type() == CV_8UC1 in function 'cv::equalizeHist' FindContours 仅支持 CV_8UC1 图像 - FindContours supports only CV_8UC1 images 为什么 openCV2 的 Line (antialiased) 函数在 CV_16UC1 和 CV_8UC1 上给出不同的结果而没有溢出 - Why the Line (antialiased) function of openCV2 gives different results on CV_16UC1 and CV_8UC1 without overflow
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM