Monday, July 6, 2015

Sublime package control for Windows

Sublime is a popular editor. As many people already noticed that the following link provides a good introduction and tutorial for the power of Sublime. Because the instructor is using Sublime in MacOSX, therefore the video screen casting is more MacOSX user intuitive. Especially for package control for Windows users, which is the fundamental part for episodes after 2.9.

As we noticed the most popular package control for Sublime is: wbond (https://packagecontrol.io/installation), with the instruction for manual installation as below:

  1. Click the Preferences > Browse Packages… menu
  2. Browse up a folder and then into the Installed Packages/ folder
  3. Download Package Control.sublime-package and copy it into the Installed Packages/ directory
  4. Restart Sublime Text

But I found the step 2 and step 3 is actually not accurate for Windows.

  • For step 2 we could just ignore, in Windows, the folder you opened from step 1 is where you would like to put your package control in.
  • For step 3, after we download, you would like to release the zip file into a folder called "Package control" and copy that folder into step 1 opened location

Tuesday, May 20, 2014

Come back note and How to set GIT url password with special character

Haven't written a blog for a long time since I joined Microsoft. But I still believe, blog is a good place to share my learning and do potential benefits to other people. Let more people to have shorter learning curve as what I did. : ) 

Since I moved to Seattle, a lot has been changed in my life, therefore, this blog will not only about techniques, but also some home owner saving and maintenance tips as well. 

Hope everyone could enjoy. 

As a small benefits, sharing a a small hint, if you don’t know that already. :) 

Every time we push or pull in Git Command Line, we need to type in our username and password, this would be less desirable for us. Especially in windows, there is no out-of-box supporting for SSH for GIT. Therefore, using HTTPS could be a good alternative. 

For example in OpenCV, type in the following command line in Git we could set up the automation.  

git remote set-url origin https://username:password@github.com/username/opencv.git

But our issue is that some password may have special characters, such as #, $, @, this will break the url flow. The solution is just replace these special characters with url  encoding, (http://www.w3schools.com/tags/ref_urlencode.asp)

As an example, username: blastevil and password: blastevil@2014, the Git command line should be:  (@ in url encoding is %40)


git remote set-url origin https://blastevil:blastevil%402014@github.com/blastevil/opencv.git

Friday, January 10, 2014

How to find your Outlook 365 SMTP, POP and IMAP settings

Recently, I was attempting to send automatic emails through Python smtplib. It requires your email account's SMTP Server:

For google, it is: smtp.google.com:587

For you outlook office 365 account, you could find them through the following steps:

outlook.office365.com, log into your account.
On the right upper corner select Option,
On your account page you would see the link of " Setting for POP and IMAP"
There, you could see all your SMTP, POP and IMAP settings

Thursday, September 12, 2013

How to redefine / re-map keyboard in Windows

  In real life you may have some very inconvenient keyboard, or some applications may prefer
very frequently used keys for a very weak finger (such as Cntl in Emacs v.s Cntl is usually assign to you little finger).

  In Mac OSX you could easily reassign the keys in system administrator. But for Windows the original system does not provide such interface. There were some tool on the website you could easily find and use to modify the mapping. But if you want to map whatever you want and control everything by yourself. You may want to have a look at this blog.

  The following two links has provide useful introduction on how to modify the mapping through  Windows register. But they may not be very fully correctly. That's why I post this blog.
 
  Links:
  1. Download scan code reference from:
     http://msdn.microsoft.com/en-us/library/windows/hardware/gg463372.aspx
  2. Follow the instruction to change the register keys:
     http://www.howtogeek.com/howto/windows-vista/disable-caps-lock-key-in-windows-vista/

  Detailed Process:
 
  1. Find the related scan code file from the previous link 1 around page 33
     For example:
     Right Alt(scan 1 make) => E0 38
     Left Cntl(scan 1 make) => 1D    
  2. According to the instruction on previous link 2:
     Make from Right Alt => left Cntl should be (Scancode Map):
    
     0000 0000 0000 0000 0200 0000 1D00 38E0
     0000 0000
    
     There are two points need to notice:
     1. E0 38 should be reverse order as: 38 E0
     2. 1D    is actually short for 00 1D. Then revert the order in 8bit into 1D 00

  3. Generalizations
     The following three mappings:
     1. Right Alt => Left Cntl
     2. Right Win => Left Cntl
     3. Insert    => Nothing (0000)
    
     0000 0000 0000 0000 0400 0000 1D00 38E0
     1D00 5CE0 0000 52E0 0000 0000

Thursday, May 9, 2013

Progress bar for Console program

During processing a bunk of computation, people always eager to know how far from finish. The progress bar is exactly design for it.

Console program does not support those fancy GUI, therefore something like below might be preferred.

[======>                    ] 37%

The following code should be able to help you accomplish it.
Generally speaking, you could call this function as below:
PS:
You could also get access to this code at: https://gist.github.com/lbl1985/5552400
It is also part of my toolbox_c at: https://github.com/lbl1985/toolbox_c

Wednesday, May 8, 2013

Could not open Video in Windows with OpenCV precompiled dlls

Issue as described in the title. 
The reason is simple, the system need opencv_ffmpeg2**.dll to read video. Just add the bin folder into system path, or directly copy this .dll file into the folder where the executable file generated.

Thursday, April 18, 2013

armadillo to other data format conversion

Armadillo is a C++ linear algebra library, especially for computer vision application.

Armadillo is more similar to MATLAB with decent performance. (check http://nghiaho.com/?p=1726 for comparison).

We may want to cooperate Armadillo with OpenCV, STL or FFTW. In this blog the conversion between STL and OpenCV will be described.

1. armadillo to STL vector
2. Armadillo to OpenCV, Since OpenCV data is saved in row-wised, and armadillo data is saved in column-wised, therefore, when we convert the data, we may need to do transformation at first. The following is the sample code.
3. OpenCV to Armadillo

4. STL 2D vector (vector<vector<T> >) to Opencv cv::Mat 2D matrix
Hope these could be helpful for some one is seeking the answer~~



Tuesday, April 2, 2013

Read ViPer data into MATLAB

ViPer as a ground truth labeling software and protocol has been widely used in computer vision community, such as UCF Youtube dataset. However, since the ground truth information has been stored in XML format, for those who are not familiar with XML and using MATLAB for experiments, this protocol may raise some difficulty.

This blog will give an example of how to read the XML ground truth information into MATLAB.

The example xml file will be the 'v_biking_13_05.xgtf' from UCF Youtube dat set, with bounding box annotation (http://www.cs.ucf.edu/~liujg/YouTube_Action_dataset.html).

1.  download viper-gt.jar from http://viper-toolkit.sourceforge.net, click ViPER Light Distribution (Recommended) [May 25, 2005] under Software section.

In MATLAB type in the following command
>> javaaddpath(' ViPER_Folder/viper-gt.jar')

2. Type in the following commands to obtain an viper object, replace the filename as your v_biking_13_05.xgtf with the path.


>> docBuilder = DocumentBuilderFactory.newInstance();
>> docBuilder.setNamespaceAware(true);
>> docElement = docBuilder.newDocumentBuilder().parse(filename).getDocumentElement();
>> parser = viper.api.impl.ViperParser;
>> objviper = parser.parseDoc(docElement);


3. Obtain a string of bounding box information: (The getChild() may vary depend on different xgtf files, but at least for this example file it works)

str = char(objviper.getChild(1).getChild(0).getChild(1).getAttribute('Location').toString);


4. parse this str as a n x 4 matrix containing BoundingBox Information
The following code should be able to help you to do this job.


function BB = parseStr(str)

dq = strfind(str, '"'); % double quote locations
bn = strfind(str, ')'); % brace number
if ( length(dq) / 2 ~= length(bn) )
    error('dq should be equal to 2 * bn');
end
BB = [];
for i = 1 : length(bn)
    tmpBB = parseOneSeg(str( dq( (i-1) * 2 + 1) + 1 : bn(i) - 1) );
    BB = cat(1, BB, tmpBB);
end

end

function tmpBB = parseOneSeg(str)
dq = strfind(str, '"');
BB = parseBB(str(1 : dq - 1) );

strNum = str2num( str( strfind(str, '[') + 1 : strfind(str, ',') - 1) );
endNum = str2num( str( strfind(str, ', ') + 2 : length(str) ) );
tmpBB = repmat(BB, endNum - strNum, 1);
end

function BB = parseBB(str)
BB = zeros(1, 4);
sp = strfind(str, ' '); % space location
sp = [0 sp length(str)+1];
for i = 1 : 4
    BB(i) = str2num( str( sp(i)+1 : sp(i+1) - 1) );
end
end


5. Last you may want to visualize the bounding box
The following small script may help you to do that.


function readViper_visualize(BB, videoName)

video = VideoReader(videoName);

nFrame = video.NumberOfFrames;
nRow = size(BB, 1);
n = min(nFrame, nRow);

% BB = BB(:, [3 4 1 2]);

for i = 1 : n
    I = read(video, i);
    imshow(I);
    rectangle('Position', BB(i, :), 'EdgeColor', 'r', 'LineWidth', 3);
    title(['Frame ' num2str(i)]);
end



Tuesday, February 26, 2013

OpenCV combine two images

In computer vision community, developer always face one basic task to visualize the correspondences between two frames, and the easier solution might be combine two images into one single image.

In this blog, I will give a convenient and easy to understand solution to solve this problem. Of course, so far, this is just a simple starting point, you could extent it to make more robust.

The code would be as follow:


struct myexception : public std::exception{
    std::string s;
    myexception(std::string ss):s(ss){}
    virtual const char* what() const throw() {return s.c_str();}
    ~myexception() throw(){}
};



// combine two identical size images into one big image
void combineTwoImages(cv::Mat &dst, const cv::Mat img1, const cv::Mat img2){
    if (img1.cols != img2.cols || img1.rows != img2.rows) {
        throw myexception("img1 and img2 should be identical size");
    }
    int rows = img1.rows;
    int cols = img1.cols;
    dst = cvCreateMat(rows, 2 * cols, img1.type());
    cv::Mat tmp = dst(cv::Rect(0, 0, cols, rows));
    img1.copyTo(tmp);
    tmp = dst(cv::Rect(cols, 0, cols, rows));
    img2.copyTo(tmp);
}


As you could notice, this code would only work for identical size case, you would extent it to handle two arbitrary size images as well.

PS: cv::Rect(x, y, _width, _height)

Hope this would be helpful.

Install PCL and first project in XCode

PCL (Point Cloud Library) is getting more popular these days. It's good for Kinect users and might be also helpful for visualization usages as well.

I used to attempt to install the PCL, couple months ago, however at that time it's not very successful. This time, it works. For my record and for others who may interested, I will list the details below.

1. Following the instruction in: http://pointclouds.org/documentation/tutorials/compiling_pcl_macosx.php#compiling-pcl-macosx
till installing Qhull.
2. Install and download libusb, openNI and sense from the following webpage ( do not install libusb from macports):
http://pointclouds.org/downloads/macosx.html
3. Build PCL as the instruction in Step 1 webpage.

The first project in Xcode:

0.1 Switch Compiler for C/C++/Objective-C from Apple LLVM compiler 4.2 -> LLVM GCC 4.2

1. adding the following entries into "Header Search Paths"
1.1 /usr/local/include/pcl-1.7
1.2 /opt/local/include
1.3 /opt/local/include/eigen3
1.4 /opt/local/include/vtk-5.10



2. Adding "New Group", named: boost, right-click new created "boost" folder, and Add File to project:
locate file: /opt/local/lib/libboost_system-mt.dylib

3. Adding "New Group", named: pcl, right-click new created "pcl" folder, and Add File to project:
locate file: ($whereBuildPCL)/build/lib/libpcl_io.1.7.0.dylib, and ($whereBuildPCL)/build/lib/libpcl_common.1.7.0.dylib

4. input the following script into main.cpp


#include <iostream>
#include <pcl/io/pcd_io.h>
#include <pcl/point_types.h>

int main(int argc, const char * argv[])
{
    pcl::PointCloud<pcl::PointXYZ> cloud;
    // fill in the cloud data
    cloud.width = 5;
    cloud.height = 1;
    cloud.is_dense = false;
    cloud.points.resize(cloud.width * cloud.height);
    
    for (size_t i = 0; i < cloud.points.size(); ++i){
        cloud.points[i].x = 1024 * rand() / (RAND_MAX + 1.0f);
        cloud.points[i].y = 1024 * rand() / (RAND_MAX + 1.0f);
        cloud.points[i].z = 1024 * rand() / (RAND_MAX + 1.0f);
    }
    
    pcl::io::savePCDFileASCII("test_pcd.pcd", cloud);
    std::cerr << "Saved " << cloud.points.size() << " data points to test_pcd.pcd." << std::endl;
    
    for (size_t i = 0; i < cloud.points.size(); ++i)
        std::cerr << "   " << cloud.points[i].x << " " << cloud.points[i].y << " " << cloud.points[i].z << std::endl;
    
    return 0;
}

5. Find out the output .pcd file 
5.1 Open Organizer: (Window->Organizer)
5.2 find your Projects, right click the right arrow next to your "Derived Data"
5.3 Build/Products/Debug/test_pcd.pcd


Saturday, February 23, 2013

OpenCV: compare whether two Mat is identical

As MATLAB users could always conveniently compare two matrix, in order to decide whether the two matrix is identical or not.
However, in OpenCV this easy task is not straight forward as you first thought.
The underlying small openCV script could help you to address this simple task.

// return true if two matrix is identical, false otherwise


bool BasicUtil::matIsEqual(const cv::Mat mat1, const cv::Mat mat2){
    // treat two empty mat as identical as well
    if (mat1.empty() && mat2.empty()) {
        return true;
    }
    // if dimensionality of two mat is not identical, these two mat is not identical
    if (mat1.cols != mat2.cols || mat1.rows != mat2.rows || mat1.dims != mat2.dims) {
        return false;
    }
    cv::Mat diff;
    cv::compare(mat1, mat2, diff, cv::CMP_NE);
    int nz = cv::countNonZero(diff);
    return nz==0;
}


PS: I'm currently building a C++ toolbox in order to replace some basic MATLAB functionality for computer vision users. I will release it once I built a considerable functionalities.

Friday, November 23, 2012

How to read Chinese on Nook 2

Even though I am a Kindle fan, this year nook simple touch is only $49.00 from Target comparing to the regular $99.00. My wife decided to buy me one for fun.

Since nook is not selling in Chinese market officially. The Chinese support is not natively.

1. Download Sigil from: http://code.google.com/p/sigil/
2. Open a .epub file. select "Styles", click the .css file.
3. MOdify the @font-face section from :
@font-face {
font-family:"cnepub";
src:url(res:///opt/sony/ebook/FONT/tt0011m_.ttf), url(res:///tt0011m_.ttf);
}
to: 
@font-face {
font-family:"cnepub";
src:url(res:///opt/sony/ebook/FONT/tt0011m_.ttf), url(res:///tt0011m_.ttf),
url(res:///system/fonts/DroidSansFallback.ttf);
}
4. Copy the modified .epub file into your nook.
5. Open the file in nook. Click the pages like 5/233, select "text" -> check "Publisher Defaults".
Then you will notice the Chinese characters are showing up!!

Reference webpages:
1. http://www.hi-pda.com/forum/viewthread.php?tid=857877&extra=page%3D1
2. http://www.hi-pda.com/forum/viewthread.php?tid=812236
3. http://www.hi-pda.com/forum/viewthread.php?tid=800133
4. http://www.by-smart.com/forum.php?mod=viewthread&tid=2000

Wednesday, November 21, 2012

Install Emacs key-stroke in VS 2010 professional

Emacs key stroke will save operator's time for leaving keyboard fundamental key positions. This is critical for improving programmers' productivity.

Visual Studio for Emacs users might be a pain at the first glance due to the keystroke differences. This article will list the necessary information of how to utilize Emacs keystrokes in VS2010 Pro.

1. Go webpage: http://visualstudiogallery.msdn.microsoft.com/09dc58c4-6f47-413a-9176-742be7463f92/
2. Click "Download" button
3. The download file will be "EmacsEmulations.vsix"
4. Close Visual Studio 2010 Pro
5. Right click and select "open with" -> "Visual Studio 2010"
6. It should be installed automatically.
7. Re start Visual Studio 2010 Pro
8. Click OK for installation permit.
9. Go to Tools->Options-> Environment->Keyboard; Select "Emacs" from "Apply the following additional keyboard mapping scheme:"

Please pay attention to the webpage in step 1. It also includes keystrokes information you may be interested.

PS: This Emacs extension is NOT applied for VS 2010 Express version.

Friday, October 19, 2012

XCode 4.5.1 linking error with Opencv 2.4.2_1

I always keep my software updated to the latest version. Generally, it works perfectly fine. However, after I upgrade Xcode into 4.5.1 and Opencv to 2.4.2_1 though macports. The simple opencv 2.0 style compile will keep pushing out linking errors.

The solution is the attached image below, switch the selected item from libc++ (LLVM) into libstdc++(GNU C++ standard library)

Hope this is helpful.


Tuesday, October 16, 2012

Read CVML into MATLAB

CVML (CVML- An XML-based Computer Vision Markup Language), which is commonly used in AI community as the manual label format.  which is   which is commonly used in AI community as the manual label format. Popular CAVIAR and other datasets are using this as an standard. The output files will be .xml file, which might not be easy for MATLAB researchers to use. 

CoreLibrary does have a C++ based dataset to read from and write to CVML based .xml files, however, they are still not .mat file as MATLAB users expected. 
In this blog, we will utilize an easy and straight forward way to extract the objects bounding boxes.  All the knowledge are based on blog: http://www.gnebehay.com/?p=5




The first step, please use emacs or any editor you would prefer to copy and paste the following code in a file called: 'cvml_csv.xslt'.


<?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text"/>
<xsl:variable name="sep" select="' '" />
<xsl:template match="/">
      <xsl:for-each select="dataset/frame">
    <xsl:for-each select="objectlist/object">
        <xsl:value-of select="../../@number"/>
        <xsl:copy-of select="$sep" />
        <xsl:value-of select="@id"/>
        <xsl:copy-of select="$sep" />
        <xsl:value-of select="box/@xc"/>
        <xsl:copy-of select="$sep" />
        <xsl:value-of select="box/@yc"/>
        <xsl:copy-of select="$sep" />
        <xsl:value-of select="box/@w"/>
        <xsl:copy-of select="$sep" />
        <xsl:value-of select="box/@h"/>
        <xsl:value-of select="'&#xA;'"/>
    </xsl:for-each>
      </xsl:for-each>
</xsl:template>
</xsl:stylesheet>

2nd step: Let us assume, you CVML .xml file is called: fwbs1gt.xml. Then type in the following command in your terminal

                 xsltproc cvml_csv.xslt fwbs1gt.xml > fwbs1gt.csv

3rd step: read csv file into matlab, by typing the following command in MATLAB command windows.

                 A = dlmread('fwbs1gt.csv');

4th step: For A, there will be n rows 6 columns. The 1st columns is the frame number. 2nd is the object id within the frame. 3rd to 6th column is the bounding box information. 

Again, this blog is mainly for a record to myself. If you have confusion, please go to blog:  http://www.gnebehay.com/?p=5. The author has done a great work to introduce this whole topic. 
All credit goes to that author. 

prettify