Skip to content

Instantly share code, notes, and snippets.

@inoshiro
Created June 24, 2012 10:30
Show Gist options
  • Save inoshiro/2982758 to your computer and use it in GitHub Desktop.
Save inoshiro/2982758 to your computer and use it in GitHub Desktop.
OpenCVのチュートリアルをPythonでやってみた http://gihyo.jp/dev/feature/01/opencv
import cv
imgfile = '../data/members.jpeg'
im = cv.LoadImage(imgfile, 1)
cascade = cv.Load('../data/haarcascade_frontalface_default.xml')
faces = cv.HaarDetectObjects(im, cascade, cv.CreateMemStorage())
for f in faces:
cv.Rectangle(im,
(f[0][0], f[0][1]),
(f[0][0]+f[0][2], f[0][1]+f[0][3]),
cv.CV_RGB(255, 0, 0),
3)
cv.NamedWindow('kabe', 0)
cv.ShowImage('kabe', im)
cv.WaitKey(0)
cv.DestroyWindow('kabe')
import cv
kabe_file = '../data/kabe.jpeg'
im = cv.LoadImageM(kabe_file)
cv.NamedWindow('kabe', cv.CV_WINDOW_AUTOSIZE)
cv.ShowImage('kabe', im)
cv.WaitKey(0)
cv.DestroyWindow('kabe')
import cv
kabe_file = '../data/kabe.jpeg'
im_in = cv.LoadImage(kabe_file, cv.CV_LOAD_IMAGE_GRAYSCALE)
im_out = cv.CreateImage(cv.GetSize(im_in), cv.IPL_DEPTH_8U, 1)
cv.Canny(im_in, im_out, 64, 128)
cv.NamedWindow('kabe', cv.CV_WINDOW_AUTOSIZE)
cv.ShowImage('kabe', im_out)
cv.WaitKey(0)
cv.DestroyWindow('kabe')
import cv
kabe_file = '../data/kabe.jpeg'
im_in = cv.LoadImage(kabe_file, cv.CV_LOAD_IMAGE_COLOR)
im_out = cv.CreateImage(cv.GetSize(im_in), cv.IPL_DEPTH_8U, 3)
rotationMat = cv.CreateMat(2, 3, cv.CV_32FC1)
cv.GetRotationMatrix2D((im_in.height/2, im_in.width/2), 30, 1, rotationMat)
cv.WarpAffine(im_in, im_out, rotationMat)
cv.NamedWindow('kabe', cv.CV_WINDOW_AUTOSIZE)
cv.ShowImage('kabe', im_out)
cv.WaitKey(0)
cv.DestroyWindow('kabe')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment