.需要矫正的图片1

需要矫正的图

矫正后的结果:

矫正后的图

需要矫正的图片2

矫正前

矫正后

# import the necessary packages

from imutils.perspectiveimport four_point_transform

from imutilsimport contours

import numpyas np

import argparse

import imutils

import cv2

# construct the argument parse and parse the arguments

# ap = argparse.ArgumentParser()

# ap.add_argument("-i", "--image", required=True,

#    help="path to the input image")

# args = vars(ap.parse_args())

# define the answer key which maps the question number

# to the correct answer

ANSWER_KEY = {0:1,1:4,2:0,3:3,4:1}

# load the image, convert it to grayscale, blur it

# slightly, then find edges

image = cv2.imread("changeRect.png")

gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

blurred = cv2.GaussianBlur(gray, (5,5),0)

edged = cv2.Canny(blurred,75,200)

#find contours in edge map ,then initialize the contour corresponds to the document

cnts = cv2.findContours(edged.copy(), cv2.RETR_EXTERNAL,

cv2.CHAIN_APPROX_SIMPLE)

cnts = cnts[0] if  imutils.is_cv2()  else   cnts[1]

docCnt =None

# ensure that at least one contour was found

if      len(cnts) > 0:

# sort the contours according to their size in

# descending order

cnts =sorted(cnts,key=cv2.contourArea,reverse=True)

# loop over the sorted contours

for cin cnts:

# approximate the contour

peri = cv2.arcLength(c,True)

approx = cv2.approxPolyDP(c,0.02 * peri,True)

# if our approximated contour has four points,

# then we can assume we have found the paper

if len(approx) ==4:

docCnt = approx

break

# apply a four point perspective transform to both the

# original image and grayscale image to obtain a top-down

# birds eye view of the paper

paper = four_point_transform(image, docCnt.reshape(4,2))

warped = four_point_transform(gray, docCnt.reshape(4,2))

cv2.imshow("original", image)

cv2.imshow("Exam", paper)

cv2.waitKey(0)

python写透视挂_如何用Python openCV 用透视变换的方法对图像进行矫正相关推荐

  1. python写词法分析器_如何用python写一个简单的词法分析器

    编译原理老师要求写一个java的词法分析器,想了想决定用python写一个. 目标 能识别出变量,数字,运算符,界符和关键字,用excel表打印出来. 有了目标,想想要怎么实现词法分析器. 1.先进行 ...

  2. python小助手_如何用python写个人专属群聊提醒小助手?

    前言 大家还记得教会父母玩微信是什么时候吗?父母学会后,我们的生活就发生了「质」的变化,父母也许会吐槽你的微信头像不好,要你换一个头像. 最近 pk哥 又被母后大人吐槽了,原因是亲戚微信群里某个亲戚生 ...

  3. 写python脚本管理_如何用python脚本控制TPLINK路由器

    我想知道是否有一种工具可以让我连接到路由器并关闭它,然后从python脚本重新启动它.如何用python脚本控制TPLINK路由器 我知道如果我用python脚本编写:import os然后做os.s ...

  4. python vlookup 模糊_如何用python写excel中的vlookup函数?

    1.背景 Vlookup 函数,可以算是一个数据专员必须要会使用的基本函数了,确实很好用.但是你可能会注意到,Excel 一旦数据量过大,打开都费劲了,何况打开后,你还要输入公式计算,就更费劲了,此时 ...

  5. python程序写蛇_如何用Python画一条蛇

    先上效果图 最近又打算重新学习Python了, 之前也入门过Python, 但是弄完Python的开发环境后, 停留在print("hello world")阶段 非科班出身, 没 ...

  6. python怎么读_如何用Python读写文件

    前面我们已经介绍了很多Python相关的基础知识,大家是不是对Python已经有了进一步认识了呢?作为人工智能时代的热门编程语言,开始接触并学习Python的孩子越来越多,家长们都不想让自己的孩子落于 ...

  7. python批处理工具_如何用python批量处理!python批处理教程

    如何用python批量处理 def GetFileList(dir, fileList,notdeal=[]): newDir = dir    if os.path.isfile(dir): fil ...

  8. python写乘法口诀-如何用python编写乘法口诀表

    如何用python编写乘法口诀表?首先要明确一下思路,我们可以确定x,y两个变量,弄清楚其变化的规律,再使用循环嵌套实现.下面是如何用Python编写乘法口诀表的具体方法. 第一种:使用for遍历循环 ...

  9. python旅游推荐系统_如何用Python搭建一个简单的推荐系统?

    推荐系统的相关知识我们已在前文中提到,在这篇文章中,我们会介绍如何用Python来搭建一个简单的推荐系统. 本文使用的数据集是MovieLens数据集,该数据集由明尼苏达大学的Grouplens研究小 ...

最新文章

  1. vsftpd登录报530
  2. oracle like 条件拼接
  3. 2000/XP自动网络GHOST+全自动改IP
  4. Expression Blend实例中文教程(4) - 布局控件快速入门Canvas
  5. 网构软件-Internetware
  6. 程序设计与算法----递归之n皇后问题
  7. 深入Linux grep指令的详解(实用型)
  8. 如果写文档发博客,你还在用Word文档你就out了,写文档神器Markdown的前世今生来了。(持续更新,欢迎关注点赞)
  9. 电脑usb安装win11失败,如何给电脑安装win11系统
  10. RabbitMQ通过Exchange.Direct、同一个队列绑定不同的routekey实现不同的消费
  11. c语言运算符优先级表(c语言中各种运算符的优先级)
  12. html5扁平化设计库,5个大气漂亮的扁平化设计网站赏析|HTML5酷站
  13. c语言从入门到弃坑,从入门到放弃?《全面战争:三国》是怎么让我半小时内弃坑的...
  14. 增长黑客手册——03
  15. Stroke:脑白质微结构完整性可预测脑卒中预后功能恢复情况
  16. 大长今人物系列:宿命中的孤独灵魂——崔今英(转载)
  17. css路径自动加上了路径_CSS和关键路径
  18. DBA在项目中的角色
  19. Mysql 的存储过程和存储函数
  20. HTML旅游网页设计制作 DW旅游网站官网滚动网页 DIV旅游风景介绍网页设计与实现...

热门文章

  1. java中stopwatch,Java StopWatch.stop方法代碼示例
  2. W的图像处理之圆检测(2)一圆形标记点的粗定位算法
  3. .Net Framework SqlClient 数据提供程序不支持 CommandType 枚举值 512
  4. 王者荣耀不显示上次登录服务器,王者荣耀为什么我今天没有玩,账号登陆进去却显示游戏时间已用完...
  5. 研究生必备科研软件大全——下载,翻译,整理一网打尽!
  6. 嵌入式单片机基础篇(十)之Systick定时器原理及应用
  7. Win7下Nginx的安装与配置,win7nginx配置
  8. 如何做一份出色的竞品分析?
  9. URL Scheme app 跳转
  10. pandas多列筛选