久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

OpenCV 4.1.0版drawContours

OpenCV version 4.1.0 drawContours(OpenCV 4.1.0版drawContours)
本文介紹了OpenCV 4.1.0版drawContours的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我的以下代碼在 OpenCV 3.4.1 上運行良好,但現在不適用于 OpenCV 4.1.0 并出現錯誤.我不知道如何使代碼適應較新的版本,你能幫我嗎?非常感謝

I have the following code that worked well with OpenCV 3.4.1 and now is not working with OpenCV 4.1.0 and gives an error. I do not know how to adapt the code with the newer version, can you help me with that? Thanks a lot

def ImageProcessing(image):
    image = cv2.absdiff(image, background)
    h, gray = cv2.threshold(image, 65, 255, cv2.THRESH_BINARY_INV);
    gray = cv2.medianBlur(gray,5)

    kernel = np.ones((3,3), np.uint8)

    gray = cv2.erode(gray, kernel, iterations=1)#1

    des = cv2.bitwise_not(gray)
    tmp = cv2.findContours(des,cv2.RETR_CCOMP,cv2.CHAIN_APPROX_SIMPLE)
    contour, hier = tmp[1], tmp[0]

    for cnt in contour:
        cv2.drawContours(des,[cnt],0,255,-1)

    gray = cv2.bitwise_not(des)

    gray = cv2.dilate(gray, kernel, iterations=1)#1

    return gray

錯誤是

cv2.error: OpenCV(4.1.0)/io/opencv/modules/imgproc/src/drawing.cpp:2509: 錯誤: (-215:Assertion failed) npoints > 0 in function 'drawContours'

cv2.error: OpenCV(4.1.0) /io/opencv/modules/imgproc/src/drawing.cpp:2509: error: (-215:Assertion failed) npoints > 0 in function 'drawContours'

推薦答案

根據 OpenCV 版本,cv2.findContours() 有不同的返回簽名.

Depending on the OpenCV version, cv2.findContours() has varying return signatures.

在 OpenCV 3.4.X 中,cv2.findContours() 返回 3 個項目

In OpenCV 3.4.X, cv2.findContours() returns 3 items

image, contours, hierarchy = cv.findContours(image, mode, method[, contours[, hierarchy[, offset]]])

在 OpenCV 4.1.X 中,cv2.findContours() 返回 2 項

In OpenCV 4.1.X, cv2.findContours() returns 2 items

contours, hierarchy = cv.findContours(image, mode, method[, contours[, hierarchy[, offset]]])

無論版本如何,您都可以輕松獲取輪廓:

You can easily obtain the contours regardless of the version like this:

tmp = cv2.findContours(des,cv2.RETR_CCOMP,cv2.CHAIN_APPROX_SIMPLE)
contours = tmp[0] if len(tmp) == 2 else tmp[1]

這篇關于OpenCV 4.1.0版drawContours的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 国产三区视频在线观看 | 中文字幕乱码一区二区三区 | 国产精品 亚洲一区 | 日韩在线 | 成人在线小视频 | 天天艹逼网 | 天天久久 | 国产高清视频在线播放 | 精品国偷自产在线 | 国产高清精品一区二区三区 | 日韩伦理一区二区三区 | 亚洲狠狠 | 久热电影 | 免费视频一区二区 | 国产免费黄网 | 91精品国产乱码久久久久久久久 | 美女久久| 日本三级网站在线观看 | 在线一级片 | 成人h动漫精品一区二区器材 | 91九色视频 | 欧美专区日韩专区 | 亚洲综合日韩精品欧美综合区 | 在线中文字幕av | 国产精品视频一二三区 | .国产精品成人自产拍在线观看6 | 久热精品免费 | 精品无码久久久久国产 | 久久久精品网站 | 国产欧美久久精品 | 黄色网址免费在线观看 | 一区二区视频 | 国产精品亚洲精品久久 | 欧美一级片在线观看 | 欧美日韩一区二区在线观看 | 精品国产一区二区三区久久 | 国产精品国产三级国产aⅴ入口 | 日韩在线中文字幕 | 国产乱码精品一区二区三区中文 | 在线啊v| www.操com|