python opencv 二值化 计算白色像素点的实例

Rohana ·
更新时间:2024-09-21
· 770 次阅读

贴部分代码

#! /usr/bin/env python # -*- coding: utf-8 -*- import cv2 import numpy as np from PIL import Image area = 0 def ostu(img): global area image=cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # 转灰度 blur = cv2.GaussianBlur(image,(5,5),0) # 阈值一定要设为 0 !高斯模糊 ret3,th3 = cv2.threshold(blur,0,255,cv2.THRESH_BINARY+cv2.THRESH_OTSU) # 二值化 0 = black ; 1 = white # cv2.imshow('image', th3) # a = cv2.waitKey(0) # print a height, width = th3.shape for i in range(height): for j in range(width): if th3[i, j] == 255: area += 1 return area

以上这篇python opencv 二值化 计算白色像素点的实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持软件开发网。

您可能感兴趣的文章:python opencv 读取图片 返回图片某像素点的b,g,r值的实现方法Python OpenCV处理图像之图像像素点操作python画图--输出指定像素点的颜色值方法python使用PIL模块获取图片像素点的方法Python 处理图片像素点的实例



二值化 opencv 像素 Python

需要 登录 后方可回复, 如果你还没有账号请 注册新账号