generate_converter.py
Go to the documentation of this file.
00001 import roslib
00002 roslib.load_manifest('opencv_tests')
00003 
00004 import sensor_msgs.msg
00005 import cv
00006 
00007 from cv_bridge import CvBridge, CvBridgeError
00008 
00009 def generate_converter():
00010     map = []
00011     for t in ["8U", "8S", "16U", "16S", "32S", "32F", "64F" ]:
00012         for c in [1,2,3,4]:
00013             nm = "%sC%d" % (t, c)
00014             map.append((nm, nm))
00015     print "int encoding_as_cvtype(std::string encoding)"
00016     map.append(("rgb8", "8UC3"))
00017     map.append(("bgr8", "8UC3"))
00018     map.append(("rgba8", "8UC4"))
00019     map.append(("bgra8", "8UC4"))
00020     map.append(("mono8", "8UC1"))
00021     map.append(("mono16", "16UC"))
00022     print "{"
00023     for (a,b) in map:
00024         print '  if (encoding == "%s") return CV_%s;' % (a, b)
00025     print '  return -1;'
00026     print "}"
00027     fmts = [ "GRAY", "RGB", "BGR", "RGBA", "BGRA" ]
00028     print ''
00029     for src in fmts:
00030       print '  if (sourcefmt == "%s") {' % src
00031       for dst in fmts:
00032         if src != dst:
00033             print '    if (destfmt == "%s")' % dst
00034             print '      cvCvtColor(rosimg_, cvtimg_, CV_%s2%s);' % (src, dst)
00035       print '  }'
00036     print ''
00037 
00038 if __name__ == '__main__':
00039     generate_converter()


opencv_tests
Author(s): James Bowman
autogenerated on Wed Sep 2 2015 12:14:17