00001 /* 00002 * Commandline option for the FPS limiting: process-fps 00003 * 00004 * So this is the old VisionBrainComponentI with one small twist: 00005 * We run one timer for each input stream or cameraID that we monitor/receive. 00006 * Additionally, there is an ModelParam for a desired FPS delivered 00007 * to the updateFrame method. The message received immediately after 00008 * the timer counts down will be delivered and the appropriate timer 00009 * reset. For FPS -1 (the default) every frame that is received 00010 * should go be sent on, 0 means that we should send none on, and 00011 * a positive integer means that we should send that number per second 00012 * from that camera or as many as possible less than that rate. 00013 * 00014 * WHY: Well, we can turn off/rate limit intensive processing to free 00015 * up the CPU to other tasks so that we don't have a bunch of processing 00016 * that each slows down the others and results in poor overall performance. 00017 * 00018 * One additional change that might happen in the future is that this 00019 * class listens for a FPSChangeMessage or something from the GUI 00020 * or another class to tell it to change its FPS setting. This would 00021 * be extraordinarily useful if say we only want to perform some 00022 * image processing technique at a certain stage in the competition or 00023 * if we only want to process slowly to save resources most of the time, 00024 * but when something interesting happens elsewhere we should processes 00025 * faster to analyze the event. This will save on system resources and 00026 * allow us to implement more intensive algorithms without overburdening 00027 * the system. 00028 * 00029 * In the future this class will replace the old VBCI class, but 00030 * (1) I want to thoroughly test out the new changes before checking 00031 * in over the old one and potentially breaking the trunk and (2) I 00032 * do not think that this class belongs in the Robots/SeaBeeIII dir 00033 * anymore, maybe moving it to the Robots/RobotBrain dir would be 00034 * more appropriate. 00035 * 00036 * --Nick 00037 */ 00038 00039 00040 #include "Component/ModelComponent.H" 00041 #include "Component/ModelParam.H" 00042 #include "Component/OptionManager.H" 00043 #include "Media/FrameSeries.H" 00044 #include "Transport/FrameInfo.H" 00045 #include "Raster/GenericFrame.H" 00046 #include "Image/Image.H" 00047 #include "GUI/XWinManaged.H" 00048 #include "GUI/ImageDisplayStream.H" 00049 #include "Image/Image.H" 00050 #include "Image/DrawOps.H" 00051 #include "Image/Pixels.H" 00052 #include "Robots/RobotBrain/RobotBrainComponent.H" 00053 #include "Util/Timer.H" 00054 00055 #include "Ice/RobotBrainObjects.ice.H" 00056 #include "Ice/RobotSimEvents.ice.H" 00057 #include "Ice/IceImageUtils.H" 00058 #include <IceUtil/Thread.h> 00059 00060 #ifndef VISIONBRAINCOMPONENTI_H 00061 #define VISIONBRAINCOMPONENTI_H 00062 00063 //in milliseconds 00064 #define ZERO_RATE_WAIT_TIME 500 00065 00066 class VisionBrainComponentI : public RobotBrainComponent 00067 { 00068 public: 00069 00070 VisionBrainComponentI(OptionManager& mgr, 00071 const std::string& descrName = "VisionBrainComponent", 00072 const std::string& tagName = "VisionBrainComponent"); 00073 00074 ~VisionBrainComponentI(); 00075 00076 virtual void evolve(); 00077 00078 //!Get a message 00079 virtual void updateMessage(const RobotSimEvents::EventMessagePtr& eMsg, 00080 const Ice::Current&); 00081 00082 virtual void registerVisionTopics(); 00083 00084 virtual void registerVisionPublisher(const std::string& MessageTopic); 00085 00086 virtual bool publishVisionMsg(const::std::string& MessageTopic, RobotSimEvents::EventMessagePtr msg); 00087 00088 virtual void updateFrame(Image<PixRGB<byte> > img, bool isFwdCamera) {}; 00089 00090 virtual void updateFrame(Image<PixRGB<byte> > img, string cameraID) {}; 00091 00092 std::string getCameraSourceName() { return itsCameraSource.getVal();}; 00093 00094 protected: 00095 int itsFrameCount; 00096 OModelParam<int> desiredFramerate; 00097 00098 private: 00099 00100 OModelParam<std::string> itsCameraSource; 00101 Image<PixRGB<byte> > itsCurrentImg; 00102 bool itsCurrentImgFwdCam; 00103 string itsCurrentCameraID; 00104 00105 Timer timer; 00106 00107 IceUtil::Mutex itsImgMutex; 00108 00109 int lastFrameCount; 00110 }; 00111 00112 #endif