12
12
from PyQt4 .QtGui import *
13
13
import struct
14
14
import urllib2
15
+ import glob
15
16
16
17
def error ( msg ):
17
18
print msg
@@ -25,7 +26,7 @@ def colorDiff( c1, c2 ):
25
26
return max ( redDiff , greenDiff , blueDiff , alphaDiff )
26
27
27
28
def imageFromPath (path ):
28
- if ( path [:7 ] == 'http://' ):
29
+ if ( path [:7 ] == 'http://' or path [: 7 ] == 'file://' ):
29
30
#fetch remote image
30
31
data = urllib2 .urlopen (path ).read ()
31
32
image = QImage ()
@@ -34,6 +35,34 @@ def imageFromPath(path):
34
35
image = QImage ( path )
35
36
return image
36
37
38
+ def getControlImagePath (path ):
39
+ if os .path .isfile (path ):
40
+ return path
41
+
42
+ #else try and find matching test image
43
+ script_folder = os .path .dirname (os .path .realpath (sys .argv [0 ]))
44
+ control_images_folder = os .path .join ( script_folder , '../tests/testdata/control_images' )
45
+
46
+ matching_control_images = [x [0 ] for x in os .walk (control_images_folder ) if path in x [0 ]]
47
+ if len (matching_control_images ) > 1 :
48
+ error ('Found multiple matching control images for {}' .format (path ))
49
+ elif len (matching_control_images ) == 0 :
50
+ error ('No matching control images found for {}' .format (path ))
51
+
52
+ found_control_image_path = matching_control_images [0 ]
53
+
54
+ #check for a single matching expected image
55
+ images = glob .glob ( os .path .join (found_control_image_path , '*.png' ) )
56
+ filtered_images = [i for i in images if not i [- 9 :] == '_mask.png' ]
57
+ if len (filtered_images ) > 1 :
58
+ error ('Found multiple matching control images for {}' .format (path ))
59
+ elif len (filtered_images ) == 0 :
60
+ error ('No matching control images found for {}' .format (path ))
61
+
62
+ found_image = filtered_images [0 ]
63
+ print 'Found matching control image: {}' .format (found_image )
64
+ return found_image
65
+
37
66
def updateMask (control_image_path , rendered_image_path , mask_image_path ):
38
67
control_image = imageFromPath ( control_image_path )
39
68
if not control_image :
@@ -92,6 +121,8 @@ def updateMask(control_image_path, rendered_image_path, mask_image_path):
92
121
parser .add_argument ('mask_image' , nargs = '?' , default = None )
93
122
args = parser .parse_args ()
94
123
124
+ args .control_image = getControlImagePath ( args .control_image )
125
+
95
126
if not args .mask_image :
96
127
args .mask_image = args .control_image [:- 4 ] + '_mask.png'
97
128
0 commit comments