stereo_anaglyph.py
Go to the documentation of this file.
00001 #!/usr/bin/python
00002 import roslib
00003 roslib.load_manifest('stereo_anaglyph')
00004 import rospy
00005 import hrl_camera.ros_camera as rc
00006 import cv
00007 
00008 
00009 def anaglyph(left_color, right_color):
00010     left_mono = cv.CreateImage(cv.GetSize(left_color), cv.IPL_DEPTH_8U, 1)
00011     right_mono = cv.CreateImage(cv.GetSize(right_color), cv.IPL_DEPTH_8U, 1)
00012     green = cv.CreateImage(cv.GetSize(right_color), cv.IPL_DEPTH_8U, 1)
00013     result = cv.CreateImage(cv.GetSize(right_color), cv.IPL_DEPTH_8U, 3)
00014 
00015     cv.CvtColor(left_color, left_mono, cv.CV_RGB2GRAY)
00016     cv.CvtColor(right_color, right_mono, cv.CV_RGB2GRAY)
00017     cv.Merge(left_mono, green, right_mono, None, result)
00018     return result
00019 
00020 cameras = ['/wide_stereo/left/image_rect_color', 
00021            '/wide_stereo/right/image_rect_color']
00022 stereo_listener = rc.ROSStereoListener(cameras)
00023 cv.NamedWindow('stereo-anaglyph', cv.CV_WINDOW_AUTOSIZE)
00024 cv.WaitKey(10)
00025 
00026 while not rospy.is_shutdown():
00027     l, r = stereo_listener.next()
00028     red_blue = anaglyph(l, r)
00029     cv.ShowImage('stereo-anaglyph', red_blue)
00030     cv.WaitKey(10)
00031 
00032 
00033 
00034 
00035 
00036 
00037 
00038 
00039 
00040 
00041 
00042 
00043 
00044 
00045 
00046 
00047 
00048 
00049 
00050 
00051 
00052 
00053 
00054 
00055 
00056 
00057 
00058 
00059 
00060 
00061 
00062 
00063 
00064 #from opencv import cv
00065 #from opencv import highgui
00066 #from time import sleep
00067 #
00068 #def makeMagic(left, right, out):
00069 #    chans=[]
00070 #    for i in range(6):
00071 #        chans.append(cv.cvCreateImage(cv.cvGetSize(left),8,1))
00072 #    cv.cvSplit(left, chans[0], chans[1], chans[2], None);
00073 #    cv.cvSplit(right, chans[3], chans[4], chans[5], None);
00074 #    cv.cvMerge(chans[3],chans[4],chans[2], None, out);
00075 #    
00076 #    #cv.cvMerge(None,chans[1],None, None, out);
00077 #
00078 #cam=[]
00079 #def main():
00080 #    cam.append(highgui.cvCreateCameraCapture(0))
00081 #    cam.append(highgui.cvCreateCameraCapture(1))
00082 #    highgui.cvNamedWindow ("carrots", highgui.CV_WINDOW_AUTOSIZE)
00083 #
00084 #    uno=highgui.cvQueryFrame(cam[0]);
00085 #    dos=highgui.cvQueryFrame(cam[1]);
00086 #
00087 #    highgui.cvShowImage("carrots",uno);
00088 #    highgui.cvWaitKey(0);
00089 #    highgui.cvShowImage("carrots",dos);
00090 #    highgui.cvWaitKey(0);
00091 #
00092 #    merge=cv.cvCreateImage(cv.cvGetSize(uno),8,3)
00093 #    makeMagic(uno, dos, merge)
00094 #
00095 #    highgui.cvShowImage("carrots",merge);
00096 #    highgui.cvWaitKey(0);
00097 #
00098 #    while True :
00099 #        uno=highgui.cvQueryFrame(cam[0]);
00100 #        dos=highgui.cvQueryFrame(cam[1]);
00101 #        makeMagic(uno, dos, merge);
00102 #        highgui.cvShowImage("carrots",merge);
00103 #        if highgui.cvWaitKey(1)=="s":
00104 #          cam.append(cam.pop(0))
00105 #        print "tick"
00106 #
00107 #if __name__=="__main__":
00108 #  main()


stereo_anaglyph
Author(s): Hai Nguyen, Advisor: Prof. Charlie Kemp, Lab: Healthcare Robotics Lab at Georgia Tech
autogenerated on Wed Nov 27 2013 11:37:14