Skip to content

Commit 3f6b5fa

Browse files
committed
Improvements to generate mask script
- Rendered images can now be fetched from file:// urls - Control image path can be deduced by just specifying a partial match for the control image name instead of the full control image path
1 parent b6ae2e7 commit 3f6b5fa

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

scripts/generate_test_mask_image.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from PyQt4.QtGui import *
1313
import struct
1414
import urllib2
15+
import glob
1516

1617
def error ( msg ):
1718
print msg
@@ -25,7 +26,7 @@ def colorDiff( c1, c2 ):
2526
return max( redDiff, greenDiff, blueDiff, alphaDiff )
2627

2728
def imageFromPath(path):
28-
if ( path[:7] == 'http://' ):
29+
if ( path[:7] == 'http://' or path[:7] == 'file://' ):
2930
#fetch remote image
3031
data = urllib2.urlopen(path).read()
3132
image = QImage()
@@ -34,6 +35,34 @@ def imageFromPath(path):
3435
image = QImage( path )
3536
return image
3637

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+
3766
def updateMask(control_image_path, rendered_image_path, mask_image_path):
3867
control_image = imageFromPath( control_image_path )
3968
if not control_image:
@@ -92,6 +121,8 @@ def updateMask(control_image_path, rendered_image_path, mask_image_path):
92121
parser.add_argument('mask_image', nargs='?', default=None)
93122
args = parser.parse_args()
94123

124+
args.control_image = getControlImagePath( args.control_image)
125+
95126
if not args.mask_image:
96127
args.mask_image = args.control_image[:-4] + '_mask.png'
97128

0 commit comments

Comments
 (0)