OpenCV 图片矫正

实验原理:

通过使用透视变换函数 ,把一个图像投影到一个新的视平面

第一步:输入原图像的四个相应的坐标

第二步:定义目标图像中四个角点的坐标

第三步:计算透视变换矩阵

第四步:计算透视变换矩阵

详细函数解释:OpenCV 功能函数介绍-CSDN博客

实验代码:

python 复制代码
import cv2
import numpy as np


img = cv2.imread("./6667.png")

points1 = np.array([[166, 136], [632, 40], [82, 500], [660,550]],
                   dtype=np.float32)

points2 = np.array([[0, 0], [img.shape[1], 0], [0, img.shape[0]], [img.shape[1], img.shape[0]]],
                   dtype=np.float32)
M = cv2.getPerspectiveTransform(points1, points2)

img_warp = cv2.warpPerspective(img, M,(img.shape[1], img.shape[0]))


cv2.imshow("img",img)
cv2.imshow("img1",img_warp)
cv2.waitKey(0)

实验现象:

相关推荐
Wellijohn1 小时前
dict、tuple、dataclass 还是 slots?我把 6 种数据载体的 8 项开销全测了一遍
后端·python·性能优化
zhangfeng11331 小时前
2025–2026 国内 AI 赛事盘点:城市级黑客松 / AIGC 创作 / 硬件厂商赛事汇总
人工智能·aigc
bufengwangluo2 小时前
爬虫和调用 API 有什么区别?为什么优先选 API
python·网络爬虫·ip·api调用
Dmz丶2 小时前
前端转 AI 100 天 Day 54:RAG 项目实战(三)——多轮对话 + 会话管理
python
console.log('npc')2 小时前
Python第9课 类学习笔记,前端js语法对照
前端·python·学习
麦豆GEO2 小时前
本地生活同城服务如何做好GEO优化
人工智能·生活
邂逅and回眸2 小时前
具身智能入门:机器人是怎么学会干活的
人工智能·机器人
阿里云大数据AI技术3 小时前
SENSER识季 × 阿里云OpenSearch:从时尚灵感到自我表达
人工智能
the3clipse3 小时前
Windows 11 26H2 AI 功能使用指南:回顾、单击以执行与实时字幕
人工智能·windows·copilot+ pc·recall 回顾·单击以执行·实时字幕翻译·windows studio