1 Star 0 Fork 0

杨雪锋/opencv-python-5

加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
c6-1.py 797 Bytes
一键复制 编辑 原始数据 按行查看 历史
杨雪锋 提交于 2023-04-14 21:49 +08:00 . update ch6
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import numpy as np
import cv2
src =np.ones((500,500),dtype=np.uint8)
for r in range(500):
src[:, r] = (r / 500.0)*255
#设置127为全局阈值
# 二进制阈值处理
ret, th1 = cv2.threshold(src, 127, 255, cv2.THRESH_BINARY)
# 反二进制阈值处理
ret, th2 = cv2.threshold(src, 127, 255, cv2.THRESH_BINARY_INV)
ret, th3 = cv2.threshold(src, 127, 255, cv2.THRESH_TRUNC)
ret, th4 = cv2.threshold(src, 127, 255, cv2.THRESH_TOZERO)
ret, th5 = cv2.threshold(src, 127, 255, cv2.THRESH_TOZERO_INV)
# 为了输出图片
import sys
sys.path.append('..\\utils')
import utils
utils.show_img([src,th1,th2,th3,th4,th5],["orignal","THRESH_BINARY","THRESH_BINARY_INV",
"THRESH_TRUNC","THRESH_TOZERO","THRESH_TOZERO_INV"],"fig6-2.png")
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Python
1
https://gitee.com/hopeasy/opencv-python-5.git
git@gitee.com:hopeasy/opencv-python-5.git
hopeasy
opencv-python-5
opencv-python-5
master

搜索帮助