简体   繁体   English

Laplacian opencv 因 cv2.error 失败:OpenCV(4.1.2)

[英]Laplacian opencv fails with cv2.error: OpenCV(4.1.2)

I am trying to apply laplacian to a median filter output to get a sharper image, by later processing.我正在尝试将 laplacian 应用于中值滤波器输出以获得更清晰的图像,通过后期处理。 The code snippet is as below :代码片段如下:

img = plt.imread('example.png')
img_res = cv.resize(img,(256,256))
gray_image = cv.cvtColor(img_res, cv.COLOR_BGR2GRAY)
median_img = median_filter(gray_image, 5)
# Calculate the Laplacian
lap_img = cv.Laplacian(median_img,cv.CV_64F)

The input image is a RGB medical image.输入图像是 RGB 医学图像。 I am faced with the following error, when running this code:运行此代码时,我遇到以下错误:

 cv2.error: OpenCV(4.1.2) C:/projects/opencv-python/opencv/modules/imgproc/src/filter.simd.hpp:3175: error: (-213:The function/feature is not implemented) Unsupported combination of source format (=5), and destination format (=6) in function 'cv::opt_AVX2::getLinearFilter'

This error occurs for any image from the dataset.数据集中的任何图像都会发生此错误。 Could you please point out what could be the issue?你能指出可能是什么问题吗? The example is followed from this link for grayscale images.该示例来自此链接,用于灰度图像。

Instead of using two different libraries ( matplotlib and opencv ), stick to using one library at a time while performing image-processing.不要使用两个不同的库( matplotlibopencv ),而是在执行图像处理时一次使用一个库。 The reason is because these two libraries use different formats to store images.原因是因为这两个库使用不同的格式来存储图像。 matplotlib uses RGB convention while opencv uses BGR . matplotlib使用RGB约定,而opencv使用BGR My guess is that you're encountering this error due to using matplotlib to load the image, and then performing operations with opencv .我的猜测是您遇到此错误是由于使用matplotlib加载图像,然后使用opencv执行操作。 Simply, loading the image using cv2.imread() instead of plt.imread() seems to fix the problem简单地说,使用cv2.imread()而不是plt.imread()加载图像似乎可以解决问题

Input -> Output输入->输出

在此处输入图片说明 在此处输入图片说明

import cv2
from scipy.ndimage.filters import median_filter
import numpy as np

img = cv2.imread('1.png')
gray_image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
median_img = median_filter(gray_image, 5)
# Calculate the Laplacian
lap_img = cv2.Laplacian(median_img,cv2.CV_64F).astype(np.uint8)

cv2.imshow('lap_img', lap_img)
cv2.imwrite('lap_img.png', lap_img)
cv2.waitKey()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 OpenCV 代码中的错误:cv2.error: OpenCV(4.5.1) - Error in OpenCV code: cv2.error: OpenCV(4.5.1) cv2.error:来自 OpenCV 代码的未知 C++ 异常 - cv2.error: Unknown C++ exception from OpenCV code cv2.error: OpenCV(4.3.0) 输入图像中的通道数无效 - cv2.error: OpenCV(4.3.0) Invalid Number of channels in input image cv2.error:完成播放视频后出现OpenCV(3.4.3)错误 - cv2.error: OpenCV(3.4.3) Error After Finish Playing Video “cv2.error:OpenCV(4.5.5):-1:错误:(-5:错误参数)在函数'line'中” - "cv2.error: OpenCV(4.5.5) :-1: error: (-5:Bad argument) in function 'line'" cv2.error:OpenCV(4.6.0):-1:错误:(-5:错误参数) - cv2.error: OpenCV(4.6.0) :-1: error: (-5:Bad argument) cv2.error: OpenCV(4.5.2) 👎 错误: (-5:Bad argument) in function 'cvtColor' - cv2.error: OpenCV(4.5.2) 👎 error: (-5:Bad argument) in function 'cvtColor' cv2.error: OpenCV(4.5.4):-1: error: (-5:Bad argument) in function 'warpPerspective' - cv2.error: OpenCV(4.5.4) :-1: error: (-5:Bad argument) in function 'warpPerspective' cv2.error: opencv(4.5.3):-1: 错误: (-5:bad argument) in function 'resize' - cv2.error: opencv(4.5.3) :-1: error: (-5:bad argument) in function 'resize' imgHsv = cv2.cvtColor(img,cv2.COLOR_BGR2HSV) cv2.error: OpenCV(4.0.0) - imgHsv = cv2.cvtColor(img,cv2.COLOR_BGR2HSV) cv2.error: OpenCV(4.0.0)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM