test_artag.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 #
00003 # Copyright (c) 2010, Georgia Tech Research Corporation
00004 # All rights reserved.
00005 #
00006 # Redistribution and use in source and binary forms, with or without
00007 # modification, are permitted provided that the following conditions are met:
00008 #     * Redistributions of source code must retain the above copyright
00009 #       notice, this list of conditions and the following disclaimer.
00010 #     * Redistributions in binary form must reproduce the above copyright
00011 #       notice, this list of conditions and the following disclaimer in the
00012 #       documentation and/or other materials provided with the distribution.
00013 #     * Neither the name of the Georgia Tech Research Corporation nor the
00014 #       names of its contributors may be used to endorse or promote products
00015 #       derived from this software without specific prior written permission.
00016 #
00017 # THIS SOFTWARE IS PROVIDED BY GEORGIA TECH RESEARCH CORPORATION ''AS IS'' AND
00018 # ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
00019 # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00020 # DISCLAIMED. IN NO EVENT SHALL GEORGIA TECH BE LIABLE FOR ANY DIRECT, INDIRECT,
00021 # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
00022 # LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
00023 # OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
00024 # LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
00025 # OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00026 # ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00027 #
00028 
00029 #  \author Martin Schuster (Healthcare Robotics Lab, Georgia Tech.)
00030 
00031 
00032 '''
00033 Created on Oct 12, 2009
00034 
00035 @author: martin
00036 '''
00037 import opencv.cv as cv
00038 import opencv.highgui as hg
00039 import webcamera
00040 import util as ut    
00041 
00042 
00043 
00044 if __name__ == '__main__':
00045     
00046     wc = webcamera.Webcamera()
00047     img = wc.get_frame()
00048     grey = cv.cvCreateImage((img.width, img.height), 8,1)
00049     hg.cvConvertImage(img, grey)
00050     
00051 #    img = hg.cvLoadImage('test.jpg')
00052 #    grey = cv.cvCreateImage((img.width, img.height), 8,1)
00053 #    hg.cvConvertImage(img, grey)
00054     
00055     file = open('test.raw', 'wb')
00056     
00057 
00058     
00059     for i in range(grey.height):
00060         for j in range(grey.width):
00061             file.write(chr(grey[i][j]))
00062             
00063     file.close()
00064     
00065     #ut.display_images([img])
00066 
00067     import subprocess
00068 
00069     output = subprocess.Popen(["/home/martin/artags/ARToolKitPlus_2.1.1/bin/simple", ""], stdout=subprocess.PIPE, env={"LD_LIBRARY_PATH": "/home/martin/artags/ARToolKitPlus_2.1.1/lib:/usr/local/lib:"}).communicate()[0]
00070     import re
00071     try:
00072         m = re.search('getARMatrix.*\n([0-9\-\.]*)  ([0-9\-\.]*)  ([0-9\-\.]*)  ([0-9\-\.]*).*\n([0-9\-\.]*)  ([0-9\-\.]*)  ([0-9\-\.]*)  ([0-9\-\.]*).*\n([0-9\-\.]*)  ([0-9\-\.]*)  ([0-9\-\.]*)  ([0-9\-\.]*)', output)
00073     except: 
00074         #sys.exc_info()[0]
00075         print "ERROR parsing ARToolKitPlus output"
00076         
00077     import numpy as np
00078     R = np.array(m.groups(),dtype=np.float)
00079     R = R.reshape(3,4)
00080     
00081     if False == np.any(R): #all elements are 0
00082         print "ERROR: failed to detect AR tag"
00083     
00084     print output
00085     print m.groups()
00086     print R
00087     
00088         
00089     from enthought.mayavi import mlab
00090     #displaz bounded 3d-points
00091     #mlab.points3d(self.pts3d_bound[0,:].A1,self.pts3d_bound[1,:].A1,self.pts3d_bound[2,:].A1,self.pts3d_bound[0,:].A1,mode='point',scale_factor=0.01,colormap='jet')#,colormap='winter'
00092    
00093     #mlab.triangular_mesh([[0,-1,0]], [[0,1,0]], [[10,1,0]], [[10,-1,0]])
00094     #mlab.mesh([0,0,10,10],[-1,1,-1,1],[0,0,0,0])
00095     
00096     import numpy as np
00097 #    v1 = np.array([0,0,0])
00098 #    v2 = np.array([100,0,0])
00099 #    mlab.triangular_mesh([[v1[0]-1,v1[0]+1,v2[0]-1,v2[0]+1]], [[v1[1]-1,v1[1]+1,v2[1]-1,v2[1]+1]], [[v1[2]-1,v1[2]+1,v2[2]-1,v2[2]+1]], [(0,1,2),(1,2,3)])
00100 #    v1 = np.array([0,0,0])
00101 #    v2 = np.array([0,100,0])
00102 #    mlab.triangular_mesh([[v1[0]-1,v1[0]+1,v2[0]-1,v2[0]+1]], [[v1[1]-1,v1[1]+1,v2[1]-1,v2[1]+1]], [[v1[2]-1,v1[2]+1,v2[2]-1,v2[2]+1]], [(0,1,2),(1,2,3)])
00103 #    v1 = np.array([0,0,0])
00104 #    v2 = np.array([0,0,100])
00105 #    mlab.triangular_mesh([[v1[0]-1,v1[0]+1,v2[0]-1,v2[0]+1]], [[v1[1]-1,v1[1]+1,v2[1]-1,v2[1]+1]], [[v1[2]-1,v1[2]+1,v2[2]-1,v2[2]+1]], [(0,1,2),(1,2,3)])
00106 
00107 
00108 
00109     v1 = np.array([0,0,0])
00110     v2 = np.array([80,0,0])
00111     v2 = np.dot(R[:,0:3],v2)
00112     mlab.triangular_mesh([[v1[0]-1,v1[0]+1,v2[0]-1,v2[0]+1]], [[v1[1]-1,v1[1]+1,v2[1]-1,v2[1]+1]], [[v1[2]-1,v1[2]+1,v2[2]-1,v2[2]+1]], [(0,1,2),(1,2,3)],color=(1,1,1))
00113 
00114     v1 = np.array([0,0,0])
00115     v2 = np.array([0,80,0])
00116     v2 = np.dot(R[:,0:3],v2)
00117     mlab.triangular_mesh([[v1[0]-1,v1[0]+1,v2[0]-1,v2[0]+1]], [[v1[1]-1,v1[1]+1,v2[1]-1,v2[1]+1]], [[v1[2]-1,v1[2]+1,v2[2]-1,v2[2]+1]], [(0,1,2),(1,2,3)],color=(1,1,1))
00118 
00119     v1 = np.array([0,0,0])
00120     v2 = np.array([0,0,80])
00121     v2 = np.dot(R[:,0:3],v2)
00122     mlab.triangular_mesh([[v1[0]-1,v1[0]+1,v2[0]-1,v2[0]+1]], [[v1[1]-1,v1[1]+1,v2[1]-1,v2[1]+1]], [[v1[2]-1,v1[2]+1,v2[2]-1,v2[2]+1]], [(0,1,2),(1,2,3)],color=(1,1,1))
00123 
00124 
00125     print 
00126     #axis
00127     mlab.triangular_mesh([[0,0,100]], [[-0.3,0.3,0]], [[0,0,0]], [(0,1,2)])
00128     mlab.triangular_mesh([[-0.3,0.3,0]], [[0,0,100]], [[0,0,0]], [(0,1,2)])
00129     mlab.triangular_mesh([[-0.3,0.3,0]], [[0,0,0]], [[0,0,100]], [(0,1,2)])
00130     mlab.show()    
00131 
00132 
00133     print 'done.'


laser_camera_segmentation
Author(s): Martin Schuster, Advisor: Prof. Charlie Kemp, Lab: Healthcare Robotics Lab at Georgia Tech
autogenerated on Wed Nov 27 2013 11:56:44