How to show images in split window in OpenCV

A typical scenario in computer vision is to show multiple images in different parts of a single window, like a split window. However, OpenCV can only display a single cv::Mat in a single window using cv::imshow(). So, to achieve what we want, we create a single cv::Mat whose size is equal to the window. We copy our multiple images into this mat at the locations we want and just display the big mat.

(Note that this is far easier than the ROI regions you would need to use with IplImage.)

This sample illustrates showing two 640x480 images side-by-side in a single window:

// 640x480 images
cv::Mat mat_1;
cv::Mat mat_2;

// Create 1280x480 mat for window
cv::Mat win_mat(cv::Size(1280, 480), CV_8UC3);

// Copy small images into big mat
mat_1.copyTo(win_mat(cv::Rect(  0, 0, 640, 480)));
mat_2.copyTo(win_mat(cv::Rect(640, 0, 640, 480)));

// Display big mat
cv::imshow("Images", win_mat);

Tried with: OpenCV 2.4.8 and Ubuntu 14.04

Advertisements

How to split in Byobu

By default, Byobu lets its terminal windows occupy all the available real estate. Sometimes, it is convenient to have two shell sessions in Byobu that are side-by-side. This is possible in Byobu by creating a vertical split or a horizontal split.

This splits the current window into two vertically or horizontally. In a vertical split, the current session is maintained in the left split, while a new shell session is opened in the right split. In a horizontal split, the current session is maintained in the top split, while a new session is opened in the bottom split.

The keyboard shortcuts for creating and switching between splits:

  • Ctrl + F2: Create a vertical split
  • Shift + F2: Create a horizontal split
  • Shift + F3 and Shift + F4: Switch forward and backward between the splits

Tried with: Byobu 5.17, Tmux 1.6 and Ubuntu 12.04 LTS

Floating windows of Visual Studio 2010

A cool feature of Visual Studio 2010 is that any window displayed in the IDE can be pulled out of the IDE as an independent floating window! Just click on the tab of the window and drag it out of the IDE. The window becomes undocked from the IDE and will now behave like an independent window.

I find it useful to use this trick along with the Windows 7 snap feature to have side-by-side code windows for comparison or collaboration. You can also pull a code window into another display in a multiple display setup. You are not limited to code windows, any other window in the IDE: solution explorer, output, call stack, or anything else can be pulled out. To dock back a floating window into the IDE, drag it back into the IDE space using its tab.

This feature is a huge leap over the older tiling and splitting methods of Visual Studio, which were quite onerous.

Reference: How to: Arrange and Dock Windows.

Visual Studio: Vertical Split of Same File

Problem

It is easy to do vertical split in Visual Studio (see here). But, it is not obvious how to display the same file in both the vertical split sections.

Solution

1. Open the file you want to display in both vertical split sections. The file is open in a tab.
2. Choose Window → New Window to create a clone of this tab. These two will now be named Main.cpp:1 and Main.cpp:2
3. Now right-click on any of the two clone tabs and choose New Vertical Tab Group.

The file is now displayed in both vertical split sections. This solution is non-obvious and calling a new tab as a new window is confusing. Hope they can fix all of this in the next release.

Tried with: Visual C++ 2010 Express and Visual Studio 2010

How to split PDF file

PDFTK can be used to easily split out pages of a PDF file into separate PDF files at the shell. It is available for both Linux and Windows.

For Windows: Ensure that PDFTK is installed and the directory of pdftk.exe is in the PATH environment variable.

For Ubuntu: PDFTK can be installed using:

$ sudo apt install pdftk

Splitting

To split a PDF file into multiple PDF files, one per page of the original PDF file, invoke:

$ pdftk foobar.pdf burst output foobar-%d.pdf

If foobar.pdf is a 2 page PDF, this splits it into foobar-1.pdf and foobar-2.pdf.

If you split often, it would be much nicer to invoke the above simply as:

$ splitpdf foobar

To be able to do that on Windows, you can turn the above invocation into a batch file:

REM splitpdf.bat
pdftk %1.pdf burst output %1-%%d.pdf

The %1 is the first input argument to the batch file invocation. And %% is the way to escape %, which is a special character in a batch file.

(via Beamer + Ipe + views)

How to split window in Eclipse

I like working with split editor windows when comparing code from 2 different sections of a file or different files. This is easy to do in Visual Studio (see here). It is just as easy in Eclipse too, though not obvious if you merely look through the menus.

[ To split a window, just grab hold of a tab and pull it to the side until it turns into a black arrow. ]

[ Leave it and it turns into a new window with a new tab group. ]

To have split windows with the same file: Choose WindowNew Editor. That creates a new tab of the open file. Pull that tab as above to split the window.

For a horizontal split, pull the tab to the bottom of the window.

Keyboard shortcut for horizontal split: Ctrl+Shift+_
Keyboard shortcut for vertical split: Ctrl+Shift+{

Tried with: Eclipse Luna 4.4.1 and Ubuntu 14.04