Open CV中的Laplacian和Sobel函数无法正常工作

时间:2019-04-05 11:30:21

标签: python python-3.x opencv

我正在尝试运行拉普拉斯函数和Sobel函数来测试视频流的边缘和渐变,但是同时运行下面提到的代码

import cv2
import numpy as np

cap = cv2.VideoCapture(0)

while(1):

    # Take each frame
    _, frame = cap.read()
    hsv = cv2.cvtColor(frame, cv2.COLOR_BGR2HSV)

    lower_red = np.array([30,150,50])
    upper_red = np.array([255,255,180])

    mask = cv2.inRange(hsv, lower_red, upper_red)
    res = cv2.bitwise_and(frame,frame, mask= mask)

    laplacian = cv2.Laplacian(frame,cv2.CV_64F)
    sobelx = cv2.Sobel(frame,cv2.CV_64F,1,0,ksize=5)
    sobely = cv2.Sobel(frame,cv2.CV_64F,0,1,ksize=5)

    cv2.imshow('Original',frame)
    cv2.imshow('Mask',mask)
    cv2.imshow('laplacian',laplacian)
    cv2.imshow('sobelx',sobelx)
    cv2.imshow('sobely',sobely)

    k = cv2.waitKey(5) & 0xFF
    if k == 27:
        break

cv2.destroyAllWindows()
cap.release()

我遇到了使用此问题的错误,尽管我也从Google搜索,并尝试将OpenCV 4的版本降级为OpenCV 3,但它在笔记本电脑上也无法正常工作并面临错误

Traceback (most recent call last):
  File "C:\Users\Misha\Desktop\test\CV\Edge Detection and Gradients.py", line 24, in <module>
    cv2.imshow('laplacian',laplacian)
cv2.error: OpenCV(4.0.0) C:\projects\opencv-python\opencv\modules\highgui\src\window_w32.cpp:1230: error: (-215:Assertion failed) dst.data == (uchar*)dst_ptr in function 'cvShowImage'

对此,任何有用的建议都会有很大帮助。

0 个答案:

没有答案