Making an OpenCV RT-Component (Flip component)

Making an OpenCV RT-Component (Flip component)

This section describes creating an RT-Component to invert an image using the OpenCV library and VC9:
  • The cvFlip() function
  • Component outline
  • Operating and development environment
  • Generate the Flip component template
  • Implement the component activities
  • Test the component

The cvFlip() function

The cvFlip() function flips a 2D array (i.e. an image) on the vertical axis, horizontal axis, or both axes at the same time.

 void cvFlip(IplImage* src, IplImage* dst=NULL, int flip_mode=0);
 #define cvMirror cvFlip
  
 src       Input array
 dst       Output array. If dst is NULL, the result will be written into src.
 flip_mode Flag setting the axes to flip on.
  flip_mode = 0: Flip on the X axis (swap top and bottom)
  flip_mode > 0: Flip on the Y axis (swap left and right)
  flip_mode < 0: Flip on both axes

Component outline

The component will flip an image received by an InPort and output it on an OutPort.
The flip mode will be controlled by an RTC configuration parameter called "flip_mode." Set flip_mode as below:

  • Flip on the X axis: 0
  • Flip on the Y axis: 1
  • Flip on both axes: -1


The specification of the component we will create is as follows:

  • InPort
    • Captured image data (TimedOctetSeq)
  • OutPort
    • Flipped image data (TimedOctetSeq)
  • Configuration
    • Flip mode (int)

※ TimedOctetSeq is a data type specified in BasicDataType.idl from OpenRTM-aist.

※ octet is a CORBA IDL base type that can store and transmit any data in 8-bit format without transformation.

   struct Time
  {
        unsigned long sec;    // sec
        unsigned long nsec;   // nano sec
  };
 
   struct TimedOctetSeq
  {
        Time tm;
        sequence<octet> data;
  };


Figure 1 illustrates the effects of different flip_mode settings.


cvFlip_and_FlipRTC.png
Figure 1. The effect of setting flip_mode in the Flip component.


Operating environment and development environment

  • Decompression tool (e.g. Lhaplus)

Generate the Flip component template

We will generate the Flip component template using RTCBuilder.

Starting RTCBuilder

Upon starting Eclipse with a new workspace, the Welcome page will be displayed.

fig1-1EclipseInit.png
Figure 2. Eclipse first-time startup screen.


Close this Welcome screen using the close button to display the default perspective view.

fig2-2PerspectiveSwitch.png
Figure 3. Changing perspective.


Click the "Open Perspective" button in the top right and select "Other..." from the menu.

fig2-3PerspectiveSelection.png
Figure 4. Perspective selection.


Select "RTC Builder".

fig2-4RTCBuilderInit.png
Figure 5. The RTC Builder start screen.


Making an RTCBuilder project

First, we will make an Eclipse project for the RT-Component. From the File menu, select "New," then "Project."

fig2-5CreateProject.png
Figure 6. Making an RTCBuilder project, step 1.


In the displayed dialog, select "Other," then "RTCBuilder" (RTC ビルダ) and click "Next".

fig2-6CreateProject2.png
Figure 7. Making an RTCBuilder project, step 2.


Enter a project name and click "Finish."

fig2-7CreteProject3.PNG
Figure 8. Making an RTCBuilder project, step 3.


A project using the given name will be created and displayed in the package explorer.

fig2-8CreateProject4.png
Figure 9. Making an RTCBuilder project, step 4.


Within the generated project will be an RTC profile XML (RTC.xml) containing default values.

Starting the RTC Profile Editor

To open the RTC Profile Editor, click the "Open New RtcBuilder Editor" button on the toolbar, or select "Open New Builder Editor" from the File menu.

fig2-9ToolsBarOpenNewRtcBuilder.png
Figure 10. "Open New RtcBuilder Editor" on the toolbar.



fig2-10FileMenuOpenNewBuilder.png
Figure 11. "Open New Builder Editor" entry in the File menu.


Data type definition files location

It is necessary to set the location of the IDL files that define data types used by data ports and service ports.
※ This value is valid for the entire workspace, so it does not need to be set for each project created within the same workspace.

 1. Open the settings dialog by selecting "Settings" from the "Window" menu.
 2. Expand the "RtcBuilder" branch and select "Data Type."
 3. Click the "Add" button and enter values for "IDL File Directories." IDL files included with OpenRTM-aist are installed to this path by default:
     
      C:\Program Files\OpenRTM-aist\1.0\rtm\idl
 
 4. Click the "OK" button to finish.


RTCBuilder_datatype_setup.png
Figure 12. Data file location settings dialog.


Entering the component profile and generating code

1. Select the "Basic" (基本) tab, and enter the basic component information as below.


-Module name: Flip
  • Module description: Flip image component
  • Module version: 1.0.0
  • Module vender: AIST
  • Module category: Category
  • Component type: STATIC
  • Component's activity type: PERIODIC
  • Component kind: DataFlowComponent
  • Number of maximum instance: 1
  • Execution type: PeriodicExecutionContext
  • Execution Rate: 1.0
    -Output Project: Flip


RTCBuilder_base.png
Figure 13. Entering basic component information.


2. Select the "Activity" (アクティビティ) tab and select the action callbacks that will be used.

For the Flip component, the onActivated(), onDeactivated() and onExecute() callbacks will be used. Check them as in Figure 14.


RTCBuilder_activity.png
Figure 14. Selecting activity callbacks.


3. Select the ""Data port" (データポート) tab and enter the data port information.


-InPort Profile:
    • Port Name: original_image
    • Data Type: TimedOctetSeq
    • Var Name: image_orig
    • Disp. Position: left
      -OutPort Profile:
    • Port Name: fliped_image
    • Data Type: TimedOctetSeq
    • Var Name: image_flip
    • Disp. Position: right


RTCBuilder_dataport.png
Figure 15. Entering the data port information.


4. Select the "Configuration" (コンフィギュレーション) tab and enter the configuration parameters.


-flip_mode
    • Name: flip_mode
    • TYpe: int
    • Default Value: 1
    • Variable name: flip_mode

-image_height
    • Name: image_height
    • TYpe: int
    • Default Value: 240
    • Variable name: img_height

-image_width
    • Name: image_width
    • TYpe: int
    • Default Value: 320
    • Variable name: img_width


RTCBuilder_config.png
Figure 16. Entering configuration parameters.


5. Select the "Language/Environment" (言語・環境) tab and choose a programming language. For the Flip component, choose C++.


RTCBuilder_lang.png
Figure 17. Programming language selection


6. Click the "Generate code" (コード生成) button in the "Basic" tab to generate the component template.


RTCBuilder_base.png
Figure 18. Template generation.


※ The component template code will be generated in the currently-active Eclipse workspace directory. You can check this directory by selecting "Change workspace" from the File menu.

Download

latest Releases

For Begginers

Windows msi(installer) package (only trying samples)

C++,Python,Java,
Toolsを含む
1.2.1-RELEASE

Development environment is required for RT-Component development. See download page for details.

Number of Projects

Choreonoid

Motion editor/Dynamics simulator

OpenHRP3

Dynamics simulator

OpenRTP

Integrated Development Platform

AIST RTC collection

RT-Components collection by AIST

TORK

Tokyo Opensource Robotics Association

DAQ-Middleware

Middleware for DAQ (Data Aquisition) by KEK