打开 cv 发现奇怪的轮廓

时间:2021-02-05 13:20:53

标签: python-3.x opencv

我用树莓派相机克隆拍了一张照片,想在里面找到轮廓。OpenCV 似乎没有找到我期望的轮廓。我的代码有错误吗?

WebElement fileupload = driver.findElement(By.cssSelector(".icon-upload-cloud"));
    fileupload.click();    
    StringSelection ss = new StringSelection("C:\\Users\\Vinicius\\OneDrive\\Arquivos para códigos\\Arquivo de áudio.mp3"); 
    Toolkit.getDefaultToolkit().getSystemClipboard().setContents(ss, null);                                     
    Robot robot = new Robot();
    robot.keyPress(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_V);
    robot.keyRelease(KeyEvent.VK_V);
    robot.keyRelease(KeyEvent.VK_CONTROL);
    robot.keyPress(KeyEvent.VK_ENTER);
    robot.keyRelease(KeyEvent.VK_ENTER);

enter image description here

提前致谢:)。 干杯

1 个答案:

答案 0 :(得分:1)

缺少的步骤是应用 threshold

阈值结果将是:

enter image description here

现在找到轮廓:

enter image description here

代码:


import cv2

img = cv2.imread("bugs.png")
gry = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
thr = cv2.threshold(gry, 0, 255, cv2.THRESH_BINARY_INV | cv2.THRESH_OTSU)[1]
cnt, _ = cv2.findContours(thr, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
cv2.drawContours(img, cnt, -1, (0, 0, 255), thickness=1)
cv2.imshow("img", img)
cv2.waitKey(0)
相关问题