Allow remote urls for generate_test_mask_image.py

This commit is contained in:
Nyall Dawson 2015-06-16 21:35:19 +10:00
parent cf2fa39691
commit a378627bfa

View File

@ -11,6 +11,7 @@ import argparse
from PyQt4.QtCore import * from PyQt4.QtCore import *
from PyQt4.QtGui import * from PyQt4.QtGui import *
import struct import struct
import urllib2
def error ( msg ): def error ( msg ):
print msg print msg
@ -22,13 +23,23 @@ def colorDiff( c1, c2 ):
blueDiff = abs( qBlue( c1 ) - qBlue( c2 ) ) blueDiff = abs( qBlue( c1 ) - qBlue( c2 ) )
alphaDiff = abs( qAlpha( c1 ) - qAlpha( c2 ) ) alphaDiff = abs( qAlpha( c1 ) - qAlpha( c2 ) )
return max( redDiff, greenDiff, blueDiff, alphaDiff ) return max( redDiff, greenDiff, blueDiff, alphaDiff )
def imageFromPath(path):
if ( path[:7] == 'http://' ):
#fetch remote image
data = urllib2.urlopen(path).read()
image = QImage()
image.loadFromData(data)
else:
image = QImage( path )
return image
def updateMask(control_image_path, rendered_image_path, mask_image_path): def updateMask(control_image_path, rendered_image_path, mask_image_path):
control_image = QImage( control_image_path ) control_image = imageFromPath( control_image_path )
if not control_image: if not control_image:
error('Could not read control image {}'.format(control_image_path)) error('Could not read control image {}'.format(control_image_path))
rendered_image = QImage( rendered_image_path ) rendered_image = imageFromPath( rendered_image_path )
if not rendered_image: if not rendered_image:
error('Could not read rendered image {}'.format(rendered_image_path)) error('Could not read rendered image {}'.format(rendered_image_path))
if not rendered_image.width() == control_image.width() or not rendered_image.height() == control_image.height(): 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):
rendered_image.height())) rendered_image.height()))
#read current mask, if it exist #read current mask, if it exist
mask_image = QImage( mask_image_path ) mask_image = imageFromPath( mask_image_path )
if mask_image.isNull(): if mask_image.isNull():
print 'Mask image does not exist, creating' print 'Mask image does not exist, creating'
mask_image = QImage( control_image.width(), control_image.height(), QImage.Format_ARGB32 ) mask_image = QImage( control_image.width(), control_image.height(), QImage.Format_ARGB32 )