首页 > 其他 > 详细

opencv中的图形查找统计米粒数量

时间:2020-01-23 18:44:26      阅读:334      评论:0      收藏:0      [点我收藏+]
 1 # Author:Winter Liu is coming!
 2 import cv2 as cv
 3 import numpy as np
 4 import matplotlib.pyplot as plt
 5 
 6 
 7 src = cv.imread(r"C:\PycharmProjects\OpenCV\pic\rice.png")
 8 cv.imshow("original", src)
 9 gray = cv.cvtColor(src, cv.COLOR_BGR2GRAY)
10 gray = cv.GaussianBlur(gray, (3, 3), 0)
11 ret, thresh = cv.threshold(gray, 50, 255, cv.THRESH_BINARY)
12 contours, hierarchy = cv.findContours(thresh, cv.RETR_EXTERNAL, cv.CHAIN_APPROX_SIMPLE)
13 copy_img = src.copy()
14 cv.drawContours(copy_img, contours, -1, (255, 0, 0), 2)
15 cv.imshow("contours", copy_img)
16 print(len(contours))
17 
18 cv.waitKey(0)
19 cv.destroyAllWindows()

技术分享图片

技术分享图片

opencv中的图形查找统计米粒数量

原文:https://www.cnblogs.com/nmucomputer/p/12231008.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!