File: match.py

package info (click to toggle)
opencv 2.1.0-3%2Bsqueeze1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 68,800 kB
  • ctags: 52,010
  • sloc: cpp: 554,793; xml: 475,942; ansic: 153,396; python: 18,622; sh: 428; makefile: 111
file content (60 lines) | stat: -rwxr-xr-x 1,348 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
"""
This script will compare tho images and decides with a threshold
if these to images are "equal enough"
"""

# import the necessary things for OpenCV
from cv import *
from highgui import *

import frames
import sys
import os

PREFIX=os.path.join(os.environ["srcdir"],"../../opencv_extra/testdata/python/images/")


DisplayImages=False

if DisplayImages:
	videowindow="video"
	referencewindow="reference"
	cvNamedWindow(videowindow,CV_WINDOW_AUTOSIZE)
	cvNamedWindow(referencewindow,CV_WINDOW_AUTOSIZE)

# returns True/False if match/non-match
def match( image, index, thres ):

# load image from comparison set
	QCIFcompare=cvLoadImage(PREFIX+frames.QCIF[index])

	if QCIFcompare is None:
		print "Couldn't open image "+PREFIX+frames.QCIF[index]+" for comparison!"
		sys.exit(1)

# resize comparison image to input image dimensions
	size=cvSize(image.width,image.height)
	compare=cvCreateImage(size,IPL_DEPTH_8U,image.nChannels)
	cvResize(QCIFcompare,compare)

# compare images
	diff=cvNorm( image, compare, CV_RELATIVE_L2 )

	if DisplayImages:
		cvShowImage(videowindow,image)
		cvShowImage(referencewindow,compare)
		if diff<=thres:
			cvWaitKey(200)
		else:
			print "index==",index,": max==",thres," is==",diff
			cvWaitKey(5000)

	cvReleaseImage(QCIFcompare)
	cvReleaseImage(compare)

	if diff<=thres:
		return True
	else:
		return False