吴裕雄 实战PYTHON编程(9)
import cv2
cv2.namedWindow("ShowImage1")
cv2.namedWindow("ShowImage2")
image1 = cv2.imread("F:\\pythonBase\pythonex\\ch10\\media\\img01.jpg")
#image1 = cv2.imread("media\\img01.jpg", 1)
image2 = cv2.imread("F:\\pythonBase\pythonex\\ch10\\media\\img01.jpg", 0)
cv2.imshow("ShowImage1", image1)
cv2.imshow("ShowImage2", image2)
# cv2.waitKey()
cv2.waitKey(10000)
cv2.destroyAllWindows()
import cv2
cv2.namedWindow("ShowImage")
image = cv2.imread("F:\\pythonBase\pythonex\\ch10\\media\\img01.jpg", 0)
cv2.imshow("ShowImage", image)
cv2.imwrite("F:\\pythonBase\pythonex\\ch10\\img01copy1.jpg", image)
cv2.imwrite("F:\\pythonBase\pythonex\\ch10\\img01copy2.jpg", image, [int(cv2.IMWRITE_JPEG_QUALITY), 50])
cv2.waitKey(10000)
cv2.destroyWindow("ShowImage")
import cv2, numpy
cv2.namedWindow("plot")
image = cv2.imread("F:\\pythonBase\pythonex\\ch10\\media\\background.jpg")
cv2.line(image, (50,50), (300,300), (255,0,0), 2)
cv2.rectangle(image, (500,20), (580,100), (0,255,0), 3)
cv2.rectangle(image, (100,300), (150,360), (0,0,255), -1)
cv2.circle(image, (500,300), 40, (255,255,0), -1)
pts = numpy.array([[300,300],[300,340],[350,320]], numpy.int32)
cv2.polylines(image, [pts], True, (0,255,255), 2)
cv2.putText(image,"background.jpg", (350,420), cv2.FONT_HERSHEY_SIMPLEX, 1, (255,255,255), 2)
cv2.imshow("plot", image)
cv2.waitKey(5000)
cv2.destroyAllWindows()
import cv2
casc_path = "C:\\Users\\acer\\Anaconda3\\envs\\python36\\Lib\\site-packages\\cv2\\data\\haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(casc_path)
imagename = cv2.imread("F:\\pythonBase\pythonex\\ch10\\media\\person1.jpg")
faces = faceCascade.detectMultiScale(imagename, scaleFactor=1.1, minNeighbors=5, minSize=(30,30), flags = cv2.CASCADE_SCALE_IMAGE)
#imagename.shape[0]:图片高度,imagename.shape[1]:图片宽度
cv2.rectangle(imagename, (10,imagename.shape[0]-20), (110,imagename.shape[0]), (0,0,0), -1)
cv2.putText(imagename,"Find " + str(len(faces)) + " face!", (10,imagename.shape[0]-5), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255,255,255), 2)
for (x,y,w,h) in faces:
cv2.rectangle(imagename,(x,y),(x+w, y+h),(128,255,0),2)
cv2.namedWindow("facedetect")
cv2.imshow("facedetect", imagename)
cv2.waitKey(0)
cv2.destroyWindow("facedetect")
import cv2
# casc_path = "C:\\ProgramData\\Anaconda3\\pkgs\\opencv3-3.1.0-py27_0\\Library\etc\\haarcascades\\haarcascade_frontalface_default.xml"
casc_path = "C:\\Users\\acer\\Anaconda3\\envs\\python36\\Lib\\site-packages\\cv2\\data\\haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(casc_path)
image = cv2.imread("F:\\pythonBase\pythonex\\ch10\\media\\person3.jpg")
faces = faceCascade.detectMultiScale(image, scaleFactor=1.1, minNeighbors=5, minSize=(30,30), flags = cv2.CASCADE_SCALE_IMAGE)
#image.shape[0]:取得图片高度,image.shape[1]:取得图片宽度
cv2.rectangle(image, (10,image.shape[0]-20), (110,image.shape[0]), (0,0,0), -1)
cv2.putText(image,"Find " + str(len(faces)) + " face!", (10,image.shape[0]-5), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255,255,255), 2)
for (x,y,w,h) in faces:
cv2.rectangle(image,(x,y),(x+w, y+h),(128,255,0),2)
cv2.namedWindow("facedetect")
cv2.imshow("facedetect", image)
cv2.waitKey(10000)
cv2.destroyWindow("facedetect")
import cv2
# casc_path = "C:\\ProgramData\\Anaconda3\\pkgs\\opencv3-3.1.0-py27_0\\Library\etc\\haarcascades\\haarcascade_frontalface_default.xml"
casc_path = "C:\\Users\\acer\\Anaconda3\\envs\\python36\\Lib\\site-packages\\cv2\\data\\haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(casc_path)
image = cv2.imread("F:\\pythonBase\pythonex\\ch10\\media\\person8.jpg")
faces = faceCascade.detectMultiScale(image, scaleFactor=1.1, minNeighbors=5, minSize=(30,30), flags = cv2.CASCADE_SCALE_IMAGE)
#image.shape[0]:获取图片高度,image.shape[1]:获取图片宽度
cv2.rectangle(image, (10,image.shape[0]-20), (110,image.shape[0]), (0,0,0), -1)
cv2.putText(image,"Find " + str(len(faces)) + " face!", (10,image.shape[0]-5), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (255,255,255), 2)
for (x,y,w,h) in faces:
cv2.rectangle(image,(x,y),(x+w, y+h),(128,255,0),2)
cv2.namedWindow("facedetect")
cv2.imshow("facedetect", image)
cv2.waitKey(10000)
cv2.destroyWindow("facedetect")
import cv2
from PIL import Image
# casc_path = "C:\\ProgramData\\Anaconda3\\pkgs\\opencv3-3.1.0-py27_0\\Library\etc\\haarcascades\\haarcascade_frontalface_default.xml"
casc_path = "C:\\Users\\acer\\Anaconda3\\envs\\python36\\Lib\\site-packages\\cv2\\data\\haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(casc_path)
imagename = "F:\\pythonBase\pythonex\\ch10\\media\\person1.jpg"
image = cv2.imread(imagename)
faces = faceCascade.detectMultiScale(image, scaleFactor=1.1, minNeighbors=5, minSize=(30,30), flags = cv2.CASCADE_SCALE_IMAGE)
count = 1
for (x,y,w,h) in faces:
cv2.rectangle(image, (x,y), (x+w,y+h), (128,255,0), 2)
filename = "F:\\pythonBase\pythonex\\ch10\\" + str(count)+ ".jpg"
image1 = Image.open(imagename)
image2 = image1.crop((x, y, x+w, y+h))
image3 = image2.resize((200, 200), Image.ANTIALIAS)
image3.save(filename)
count += 1
cv2.namedWindow("facedetect")
cv2.imshow("facedetect", image)
cv2.waitKey(10000)
cv2.destroyWindow("facedetect")
import cv2
from PIL import Image
# casc_path = "C:\\ProgramData\\Anaconda3\\pkgs\\opencv3-3.1.0-py27_0\\Library\etc\\haarcascades\\haarcascade_frontalface_default.xml"
casc_path = "C:\\Users\\acer\\Anaconda3\\envs\\python36\\Lib\\site-packages\\cv2\\data\\haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(casc_path)
imagename = "F:\\pythonBase\pythonex\\ch10\\media\\person3.jpg"
image = cv2.imread(imagename)
faces = faceCascade.detectMultiScale(image, scaleFactor=1.1, minNeighbors=5, minSize=(30,30), flags = cv2.CASCADE_SCALE_IMAGE)
count = 1
for (x,y,w,h) in faces:
cv2.rectangle(image, (x,y), (x+w,y+h), (128,255,0), 2)
filename = "F:\\pythonBase\pythonex\\" + str(count)+ ".jpg"
image1 = Image.open(imagename)
image2 = image1.crop((x, y, x+w, y+h))
image3 = image2.resize((200, 200), Image.ANTIALIAS)
image3.save(filename)
count += 1
cv2.namedWindow("facedetect")
cv2.imshow("facedetect", image)
cv2.waitKey(10000)
cv2.destroyWindow("facedetect")
import cv2
from PIL import Image
# casc_path = "C:\\ProgramData\\Anaconda3\\pkgs\\opencv3-3.1.0-py27_0\\Library\etc\\haarcascades\\haarcascade_frontalface_default.xml"
casc_path = "C:\\Users\\acer\\Anaconda3\\envs\\python36\\Lib\\site-packages\\cv2\\data\\haarcascade_frontalface_default.xml"
faceCascade = cv2.CascadeClassifier(casc_path)
imagename = "F:\\pythonBase\pythonex\\ch10\\media\\person8.jpg"
image = cv2.imread(imagename)
faces = faceCascade.detectMultiScale(image, scaleFactor=1.1, minNeighbors=5, minSize=(30,30), flags = cv2.CASCADE_SCALE_IMAGE)
count = 1
for (x,y,w,h) in faces:
cv2.rectangle(image, (x,y), (x+w,y+h), (128,255,0), 2)
filename = "F:\\pythonBase\\pythonex\\" + str(count)+ ".jpg"
image1 = Image.open(imagename)
image2 = image1.crop((x, y, x+w, y+h))
image3 = image2.resize((200, 200), Image.ANTIALIAS)
image3.save(filename)
count += 1
cv2.namedWindow("facedetect")
cv2.imshow("facedetect", image)
cv2.waitKey(10000)
cv2.destroyWindow("facedetect")
吴裕雄 实战PYTHON编程(9)的更多相关文章
- 吴裕雄 实战PYTHON编程(10)
import cv2 cv2.namedWindow("frame")cap = cv2.VideoCapture(0)while(cap.isOpened()): ret, im ...
- 吴裕雄 实战PYTHON编程(8)
import pandas as pd df = pd.DataFrame( {"林大明":[65,92,78,83,70], "陈聪明":[90,72,76, ...
- 吴裕雄 实战PYTHON编程(7)
import os from win32com import client word = client.gencache.EnsureDispatch('Word.Application')word. ...
- 吴裕雄 实战PYTHON编程(6)
import matplotlib.pyplot as plt plt.rcParams['font.sans-serif']=['Simhei']plt.rcParams['axes.unicode ...
- 吴裕雄 实战PYTHON编程(5)
text = '中华'print(type(text))#<class 'str'>text1 = text.encode('gbk')print(type(text1))#<cla ...
- 吴裕雄 实战PYTHON编程(4)
import hashlib md5 = hashlib.md5()md5.update(b'Test String')print(md5.hexdigest()) import hashlib md ...
- 吴裕雄 实战python编程(3)
import requests from bs4 import BeautifulSoup url = 'http://www.baidu.com'html = requests.get(url)sp ...
- 吴裕雄 实战python编程(2)
from urllib.parse import urlparse url = 'http://www.pm25x.com/city/beijing.htm'o = urlparse(url)prin ...
- 吴裕雄 实战python编程(1)
import sqlite3 conn = sqlite3.connect('E:\\test.sqlite') # 建立数据库联接cursor = conn.cursor() # 建立 cursor ...
随机推荐
- css学习日记
相对偏移 指定left top等属性就能够够完美控制一个元素的位置 如: position:relative; left:2px; 今天遇到一个很好玩的问题,当两个并排浮动框,当一个框的长度太大时就会 ...
- 禁止HTML页面缓存
head标签里增加: <meta http-equiv="X-UA-Compatible" content="IE=8"> <meta htt ...
- 转【Oracle】一款非常好用的trace文件分析工具
[Oracle]一款非常好用的trace文件分析工具之一 北在南方 2016-04-14 11:23:58 浏览547 评论0 摘要: 介绍一款非常好用的10046分析工具--trca(Trace ...
- JQuery返回Json日期格式的問題
用JQuery Ajax返回一個Entity的Json數據時,如果Entity的屬性中有日期格式,那返回來的是一串字符串,如下圖所示: 在網上找了很久也沒有找到一個好的解決方案,最後自己寫一個java ...
- python初始环境安装
Python下载地址 Python官网:https://www.python.org/ 在该网可以下载Python最新及历史版本.可以下载基于Windows或其它操作系统的版本. Python安装 本 ...
- 开发框架:IOE 架构
ylbtech-开发框架:IOE 架构 传统的IOE架构(IBM小型机.EMC存储设备.Oracle数据库). 1.返回顶部 2.返回顶部 3.返回顶部 4.返回顶部 5.返回顶部 ...
- java study1
java安装 java优势-跨平台:一次编写,到处运行. jdk开发工具包,提供了开发人员需要的开发工具.jdk中包含了jre jre java的运行环境,负责程序的运行,jre中,包含程序运行时需要 ...
- Fragment之介绍(转)
http://www.cnblogs.com/plokmju/p/3239265.html 前言 开门见山开篇名义,本篇博客将讲解一下Android中Fragment的内容,必要的地方会提供相应的演示 ...
- 异常处理的设计与重构 pdf
百度网盘: https://pan.baidu.com/s/1hsQIEGk
- Selenium如何定位动态id的元素?
怎么定位这类型的元素呢? 根据其他属性定位如果有其他固定属性,最先考虑的当然是根据元素的其他属性来定位,定位方式那么多,何必在这一棵树上吊死.. 根据相对关系定位根据其附近的父节点.子节点.兄弟节点定 ...