貼部分代碼
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
#! /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) # 轉(zhuǎn)灰度 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 二值化 計算白色像素點的實例就是小編分享給大家的全部內(nèi)容了,希望能給大家一個參考,也希望大家多多支持服務器之家。
原文鏈接:https://blog.csdn.net/qq_38677814/article/details/79509634