Skip to content

Commit a378627

Browse files
committedJun 16, 2015
Allow remote urls for generate_test_mask_image.py
1 parent cf2fa39 commit a378627

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed
 

‎scripts/generate_test_mask_image.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
from PyQt4.QtCore import *
1212
from PyQt4.QtGui import *
1313
import struct
14+
import urllib2
1415

1516
def error ( msg ):
1617
print msg
@@ -22,13 +23,23 @@ def colorDiff( c1, c2 ):
2223
blueDiff = abs( qBlue( c1 ) - qBlue( c2 ) )
2324
alphaDiff = abs( qAlpha( c1 ) - qAlpha( c2 ) )
2425
return max( redDiff, greenDiff, blueDiff, alphaDiff )
26+
27+
def imageFromPath(path):
28+
if ( path[:7] == 'http://' ):
29+
#fetch remote image
30+
data = urllib2.urlopen(path).read()
31+
image = QImage()
32+
image.loadFromData(data)
33+
else:
34+
image = QImage( path )
35+
return image
2536

2637
def updateMask(control_image_path, rendered_image_path, mask_image_path):
27-
control_image = QImage( control_image_path )
38+
control_image = imageFromPath( control_image_path )
2839
if not control_image:
2940
error('Could not read control image {}'.format(control_image_path))
3041

31-
rendered_image = QImage( rendered_image_path )
42+
rendered_image = imageFromPath( rendered_image_path )
3243
if not rendered_image:
3344
error('Could not read rendered image {}'.format(rendered_image_path))
3445
if not rendered_image.width() == control_image.width() or not rendered_image.height() == control_image.height():
@@ -38,7 +49,7 @@ def updateMask(control_image_path, rendered_image_path, mask_image_path):
3849
rendered_image.height()))
3950

4051
#read current mask, if it exist
41-
mask_image = QImage( mask_image_path )
52+
mask_image = imageFromPath( mask_image_path )
4253
if mask_image.isNull():
4354
print 'Mask image does not exist, creating'
4455
mask_image = QImage( control_image.width(), control_image.height(), QImage.Format_ARGB32 )

0 commit comments

Comments
 (0)
Please sign in to comment.