Python 透视变换

变换前:

变换后:

import cv2
import matplotlib.pyplot as plt
import numpy as np


# 图像预处理
def detect_img(img):
    # BGR 转 RGB
    rgb_img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
    # 获取图像尺寸
    H, W = rgb_img.shape[0:2]
    # 裁剪目标区域
    split_img = rgb_img[410:620, 1020:1330]
    # 图像尺寸重制
    new_img = cv2.resize(split_img, (W // 4, H // 4))
    # RGB 转 Gray
    gray = cv2.cvtColor(new_img, cv2.COLOR_RGB2GRAY)
    # 图像阈值分割
    ret, thresh = cv2.threshold(gray, 60, 255, cv2.THRESH_BINARY)
    return H, W, rgb_img, split_img, gray, new_img, thresh


# 图像轮廓提取
def img_cnt(thresh):
    # 图像开运算
    kernel = np.ones((11, 11), np.uint8)
    open_img = cv2.morphologyEx(thresh, cv2.MORPH_OPEN, kernel)
    # 图像轮廓查
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值