changes to image comparison methods default tip
authoramit@thunder
Mon, 12 Jul 2010 15:16:52 +0530
changeset 6 d0f107095b1a
parent 5 548c6261fa00
changes to image comparison methods
testappproj/testapp/views.py
testappproj/testapp/views.pyc
--- a/testappproj/testapp/views.py	Fri Jun 25 03:59:57 2010 +0530
+++ b/testappproj/testapp/views.py	Mon Jul 12 15:16:52 2010 +0530
@@ -35,6 +35,30 @@
 from django.contrib.auth.decorators import login_required 
 from models import Score 
 from django.utils.datastructures import MultiValueDictKeyError
+from subprocess import PIPE,Popen,STDOUT
+
+
+class RGBvalues(object):
+    def __init__(self):
+        self.red=None
+        self.green=None
+        self.blue=None
+        self.alpha=None
+        self.all=None
+        self.rgb_dict=None
+    def get_values(self,output):
+         print output
+         k=re.search(r"red:.*",output,re.DOTALL)
+         all_values_string=output[k.start():k.end()]
+         self.rgb_list=re.findall('(?<=: )\d+',all_values_string) 
+         self.red=self.rgb_list[0]
+         self.green=self.rgb_list[1]
+         self.blue=self.rgb_list[2]
+         self.alpha=self.rgb_list[3]
+         self.all=self.rgb_list[4]
+         return self.rgb_list
+
+
 
 
 def respond(request, user,template, params=None):
@@ -126,9 +150,9 @@
 import pylab
 %s
 figure_conf=pylab.gcf()
-figure_conf.set_size_inches(10,10)
+figure_conf.set_size_inches(10,7.5)
 figure_conf.set_dpi(80)
-figure_conf.savefig('%s')"""%(user_code,user_image_name)
+figure_conf.savefig('%s',dpi=80)"""%(user_code,user_image_name)
 
   
   print code
@@ -152,21 +176,33 @@
   sys.stderr = sys.__stderr__
 
 
-  new_solution_image='media-root/'+str((solution_image))
-  solution_image_matrix=imread(new_solution_image)
-  print str(solution_image_matrix)
-  print user_image_name
-  user_image_matrix=imread(user_image_name)
-
-
-
-  if solution_image_matrix==user_image_matrix:
-    solved=True
+  solution_image_name='media-root/'+str((solution_image))
+#   solution_image_matrix=imread(new_solution_image)
+# #  print str(solution_image_matrix)
+# #  print user_image_name
+#   user_image_matrix=imread(user_image_name)
 
   errors=codeErr.getvalue()  
 
   codeOut.close()
   codeErr.close()
+  
+  cmd = 'compare -verbose -metric MAE %s %s null: 2>&1'%(solution_image_name,user_image_name)
+  print cmd
+  p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=STDOUT)
+  
+  output = p.stdout.read()
+  print output
+  k=RGBvalues()
+  print k.get_values(output)
+  print k.all
+
+  if k.all<=250:
+    solved=True
+  # if solution_image_matrix==user_image_matrix:
+  #   solved=True
+
+ 
 
 
   print solved
@@ -195,8 +231,10 @@
   
   sys.stderr = codeErr
  
-  sandbox.execute(code)
-
+  try:
+    sandbox.execute(code)
+  except :
+    print "ok now we are at something"
 # restore stdout and stderr
   sys.stdout = sys.__stdout__
   sys.stderr = sys.__stderr__
Binary file testappproj/testapp/views.pyc has changed