Dell Inspiron 7460 Review

For the past few months, the feeling of lugging around a 15-inch mid 2012 MacBook Pro has been something literally painful, especially for my back. I’m living a pretty mobile lifestyle now, where I have to go from one place to another, giving workshops, participating on events or attend meetings. Doing that with a 3 kg laptop on my backpack, is like asking for trouble in the future. It has been an issue for at least a year now, therefore, I’m on the market for something lighter but doesn’t hinder me from doing my regular coding practices, which most of the time, involves graphical programming.

Continue reading →

I Want More Features

One of the common problems I found when dealing with people who wants to make something, whether it’s app/website/others is that one sentence put on as the title of this post: “I Want More Features”. Said loud and proud, as if having more features equals to having a better product. Maybe it’s the direct artefact of living in an age where quantity matters? I don’t know.

In the age where everybody seems to make new app every now and then, it would be extremely hard for your digital product to shine and turn few heads to your direction. That is, unless, you design in with specific feature in mind, something that you believe would be meaningful to your product’s user. That’s why we keep on hearing the term UX design, or user-centric design, because that could be the key for your product to strive in the market. Basically you’ll want to answer 2 key questions: “What’s one central issue that you’re trying to address?” “And how can your product central feature answer it?”

And let me be honest, that’s probably the easiest part of the picture.

Continue reading →

Processing and Coding Literacy

Few months ago, I had the chance to gave workshop on making data visualization using Processing. The course were designed for someone who didn’t come from a technical background, who wished to hit the ground running making something using programming or specifically, Processing. On that day I had several people coming who are designers and architects.

For several hours, I sat there, talking, explaining, running some examples and gave short exercises for them, guiding them to the magical world of creative coding, and they did grasp it. The best thing about working with these creative people is that I could plan seed in their mind and I would instantly watch as they bend codes into their will. One guy has made his own brand identity using Processing code at that workshop. Another one, I know, is still exploring and happily tells me new things he learns.

Continue reading →

Belajar Python Bagian 2: Live Video di OpenCV dan Face Detection

Baiklah, sesuai janji saya, kali ini kita akan mempelajari bagaimana menggunakan live video di OpenCV. Kalau sebelumnya kita menggunakan gambar diam, maka kali ini kita akan menggunakan OpenCV untuk menganalisa video live dari webcam di komputer/laptop. Bisa dibilang, inilah kekuatan OpenCV, di mana ia bisa menganalisa objek bergerak, sebagaimana manusia mampu mengenali objek yang dilihat langsung.

Continue reading →

Belajar Python Bagian 1: Python dan Hello World OpenCV

Sudah beberapa bulan ini saya kesengsem lagi dengan bahasa pemrograman Python. Mungkin karena sedang getol-getolnya baca-baca soal data, statistik dan Machine Learning, jadi ingin belajar Python lagi. Maka dari itu, saya tulis blog ini sebagai catatan perjalanan saya belajar Python lagi.

Continue reading →

What Will I Learn in 2016

So, 2016 is here, I know it’s pretty late to post this sort of thing now (it’s 26th January!), but I think I need an extra motivation by writing down a reminder that’s publicly accessible. Anyway, this year I’m running full steam, working on 2 business that I co-founded. One is at Labtek Indie, an R&D company and the second one is at Framework, a company that provides IT development related courses and workshops.

With those in mind, it’s natural then for me to upgrade my skill to stay sharp in today’s era of fast moving tech. I decided to set up a short list of things to learn, so that I can master them without having to overwhelm me. Here they are:

  • Clojure. Because Labtek Indie will do a lot of rapid prototyping and after some tests and suggestions from close friend, REPL in functional paradigm will suit this. Moreover, learning a new way in thinking programmatically should benefit me., especially when crunching data in…
  • Machine learning. I suspect that this skill will help a lot of business and knowing this won’t hurt. Plus, I think it can leverage my computer vision skill. Also, I need more targeted algorithm training.
  • Meteor. Again, after running through the tutorial, I’m pretty convinced that this tool could help me rapidly build app.
  • Various front end skills. I need to keep up while brushing up on this.

I think those three should keep me in company throughout the year. I also keep a list of secret projects that could be helpful in applying those newly acquired knowledge.

Oh, and on the other hand, as a business owner, I owe myself to learn more about business, whether it’s through books or courses. So, this year is gonna be packed.

Bring it on 2016!

Installing OpenCV in Processing for Windows 7

The good thing about having Java OpenCV is we can use Processing along with many of its ease to develop computer vision application. Sure, there does exist additional library that ports Java OpenCV to make development even easier, like this OpenCV for Processing. However, having a vanilla OpenCV will allow you to learn about the inside of this library. I figure that this is a good route, teaching wise. But for something more practical, and faster to develop, please use the aforementioned library. It really is that good.

Now, installing OpenCV in Processing could not be easier. Again, I use pre-build OpenCV 2.4.11. Here are the steps:

1. Download and install Processing
2. Make a new sketch (File – New)
3. Give it a name and save it, even before you type anything
4. Now, in Windows Explorer, go to Processing sketch folder, by default it’s at “My Documents – Processing”
5. Go to where you saved your sketch
6. Now, make a folder named “code” and copy both opencv_2411.jar and opencv_java2411.dll from your opencv_directory/build/java
7. That’s it, now you can use OpenCV inside your Processing sketch.

To test it, let’s copy and paste the code from previous tutorial. It was in Java, so it should be working without any hiccup.

import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Scalar;
import org.opencv.core.Mat;
import org.opencv.highgui.Highgui;

import java.nio.*;
import java.util.List;
import java.awt.*;            
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;
import javax.swing.*;        

PImage img;
Mat mat;
Mat alpha;

void setup() {
  size(640, 480);
  background(0);
  println(Core.VERSION);
  System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
  noLoop(); //so the code only runs once

void draw() {
  mat = Highgui.imread(dataPath("fifa.png")); //put the file in data directory of your sketch
  Image imgToShow = Mat2BufferedImage(mat);
  displayImage(imgToShow);
}

BufferedImage Mat2BufferedImage(Mat m)
{
  //source: http://answers.opencv.org/question/10344/opencv-java-load-image-to-gui/
  //Fastest code
  //The output can be assigned either to a BufferedImage or to an Image

  int type = BufferedImage.TYPE_BYTE_GRAY;
  if ( m.channels() > 1 ) {
    type = BufferedImage.TYPE_3BYTE_BGR;
  }
  int bufferSize = m.channels()*m.cols()*m.rows();
  byte [] b = new byte[bufferSize];
  m.get(0, 0, b); // get all the pixels
  BufferedImage image = new BufferedImage(m.cols(), m.rows(), type);
  final byte[] targetPixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
  System.arraycopy(b, 0, targetPixels, 0, b.length);  
  return image;
}

void displayImage(Image img2)
{   
  ImageIcon icon=new ImageIcon(img2);
  JFrame frame=new JFrame();
  frame.setLayout(new FlowLayout());        
  frame.setSize(img2.getWidth(null)+50, img2.getHeight(null)+50);     
  JLabel lbl=new JLabel();
  lbl.setIcon(icon);
  frame.add(lbl);
  frame.setVisible(true);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
}

Interestingly, the amazing Bryan Chung gives different and simpler way to do it. He posted it here. Where the image’s pixel data gets read, copied into a buffer array where the colors get arranged properly, before being moved to different array. Hence, the image is being shown properly. I adapted his code here:

import org.opencv.core.Core;
import org.opencv.core.CvType;
import org.opencv.core.Scalar;
import org.opencv.core.Mat;
import org.opencv.highgui.Highgui;
 
import java.nio.*;
import java.util.List;
import java.awt.*;            // for ImageIcon type
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;
import javax.swing.*;           // for ImageIcon type
 
PImage img;
Mat mat;
Mat alpha;
 
void setup() {
  size(640, 480);
  background(0);
  println(Core.VERSION);
  System.loadLibrary(Core.NATIVE_LIBRARY_NAME);
  //noLoop();
}
 
void draw() {
  mat = Highgui.imread(dataPath("fifa.png"));
  Mat out = new Mat(mat.rows(), mat.cols(), CvType.CV_8UC4);
  alpha = new Mat(mat.rows(), mat.cols(), CvType.CV_8UC1, Scalar.all(255));
  byte [] bArray = new byte[mat.rows()*mat.cols()*4];
  img = createImage(mat.cols(), mat.rows(), ARGB);
  ArrayList ch1 = new ArrayList();
  ArrayList ch2 = new ArrayList();
 
  Core.split(mat, ch1);
 
  ch2.add(alpha);
  ch2.add(ch1.get(2));
  ch2.add(ch1.get(1));
  ch2.add(ch1.get(0));
 
  Core.merge(ch2, out);
 
  out.get(0, 0, bArray);
  ByteBuffer.wrap(bArray).asIntBuffer().get(img.pixels);
  img.updatePixels();
  image(img, 0, 0);
  out.release();
}

There you have it. In short, you just need to make a folder named “code inside your Processing sketch folder, and copy both opencv-2411.jar and opencv_java2411.dll there.

Installing Java OpenCV in Eclipse for Windows 7

This one is a bit easier, since the official guide from OpenCV is accurate and I’ve followed it without any trouble. So, you just need to do these:

  1. Download and install JDK
  2. Download and install eclipse
  3. Follow this guide from OpenCV’s website

As for testing, you can use the following code, who will do the exact same thing as in the C++ version. You may note that this code is longer than its C++ counterpart. That’s because Java OpenCV doesn’t have equivalent method for imshow() in C++. So, most of the code here are doing image conversion from Mat data type to something that Java can display.

import java.awt.*;						// for ImageIcon type
import java.awt.image.BufferedImage;
import java.awt.image.DataBufferByte;
import javax.swing.*; 					// for ImageIcon type
import org.opencv.core.Core;
import org.opencv.core.Mat;
import org.opencv.highgui.Highgui;

// This class displays image 
// Its first function converts from Mat to BufferedImage
// Second function displays the converted image
class ImageDisplayer
{
   public BufferedImage Mat2BufferedImage(Mat m)
   {
		//source: http://answers.opencv.org/question/10344/opencv-java-load-image-to-gui/
		//Fastest code
		//The output can be assigned either to a BufferedImage or to an Image
	
	   int type = BufferedImage.TYPE_BYTE_GRAY;
	   if ( m.channels() > 1 ) {
	       type = BufferedImage.TYPE_3BYTE_BGR;
	   }
	   int bufferSize = m.channels()*m.cols()*m.rows();
	   byte [] b = new byte[bufferSize];
	   m.get(0,0,b); // get all the pixels
	   BufferedImage image = new BufferedImage(m.cols(),m.rows(), type);
	   final byte[] targetPixels = ((DataBufferByte) image.getRaster().getDataBuffer()).getData();
	   System.arraycopy(b, 0, targetPixels, 0, b.length);  
	   return image;	
   }
   
   public void displayImage(Image img2)
   {   
	   ImageIcon icon=new ImageIcon(img2);
	   JFrame frame=new JFrame();
	   frame.setLayout(new FlowLayout());        
	   frame.setSize(img2.getWidth(null)+50, img2.getHeight(null)+50);     
	   JLabel lbl=new JLabel();
	   lbl.setIcon(icon);
	   frame.add(lbl);
	   frame.setVisible(true);
	   frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}
}

// This is the main class
// We load image using OpenCV as a Mat
public class hello
{
	public static void main( String[] args )
	{
	    System.loadLibrary( Core.NATIVE_LIBRARY_NAME );
		Mat img = Highgui.imread("C:\\Users\\Didit\\Pictures\\fifa.png"); //Change to any file you want
	    ImageDisplayer displayer = new ImageDisplayer();
		Image imgToShow = displayer.Mat2BufferedImage(img);
	    displayer.displayImage(imgToShow);
	}
}

I didn’t actually notice that there would be so much code in the beginning, but Java is pretty easy to read anyway. So, I don’t think this trade off should scare you from using OpenCV in Java.

Installing C++ OpenCV in Visual Studio 2012 for Windows 7

Let’s make it quick, here are the steps required. I use pre-build OpenCV 2.4.11 in a 64-bit Windows 7 machine.

Getting The OS Ready
First of all, let’s download OpenCV and do some OS-level configurations

  1. Download OpenCV
  2. Extract OpenCV to your desired folder. It’s a good idea to use the shortest path to it and keeping the version name too. Example: “D:\OpenCV-2.4.11”
  3. Open Command Prompt and type
    setx -m OPENCV_DIR D:\OpenCV\Build\x64\vc11 

    Note that this is for 64-bit Visual Studio 2012

  4. Right click on My Computer, click Properties and choose Advanced System Settings
  5. Click Environment Variables button
  6. In System variables, choose the Path Variable and click Edit button
  7. Now, type
    ;%OPENCV_DIR%\bin;

    At this point, the system knows where OpenCV is. If you need to change the directory, you just need to redo step 3 and change accordingly

Adding OpenCV to Visual Studio Project
Now, we’ll look into how to add OpenCV to a Visual Studio project. It involves adding the appropriate libraries, header files and DLLs.

Note that the official tutorial from OpenCV also suggests global mode of adding libraries. I prefer local method. For the sake of completion, I’d suggest that you go and visit that page

  1. Open Visual Studio, choose File – New Project
  2. Choose Win32 Console Application, give it a name and choose where to save it. Click Next
  3. In the next wizard window, choose Empty Project under Additional Options, just to make things cleaner. This is optional though.
  4. Now you have a basic project ready to be used. Let’s add OpenCV to it.
  5. Go to Project-$Project_Name Properties or press Alt+F7
  6. Because I want to use 64-bit, I go to Configuration Manager and change the platform to x64
  7. Next, in the Property Pages window, choose Configuration PropertiesC/C++ and under Additional Include Directories insert:
    $(OPENCV_DIR)\..\..\include
    $(OPENCV_DIR)\..\..\include\opencv2
    $(OPENCV_DIR)\..\..\include\opencv2
    
  8. Then, in Linker – Additional Library Directories insert
    $(OPENCV_DIR)\lib
  9. Now, check your Configuration on top of the Property Pages window. You can set it for Debug or Release. Make sure that you have these additional libraries for both configuration.
  10. For Debug configuration, in Linker – Input – Additional Dependencies insert these following items:
    opencv_calib3d2411d.lib
    opencv_core2411d.lib
    opencv_features2d2411d.lib
    opencv_flann2411d.lib
    opencv_highgui2411d.lib
    opencv_imgproc2411d.lib
    opencv_ml2411d.lib
    opencv_objdetect2411d.lib
    opencv_photo2411d.lib
    opencv_stitching2411d.lib
    opencv_superres2411d.lib
    opencv_ts2411d.lib
    opencv_video2411d.lib
    opencv_videostab2411d.lib
    
  11. And finally, for release, repeat the last step, insert aforementioned items, but remove the letter “d” before lib, so you have:
    opencv_calib3d2411.lib
    opencv_core2411.lib
    opencv_features2d2411.lib
    opencv_flann2411.lib
    opencv_highgui2411.lib
    opencv_imgproc2411.lib
    opencv_ml2411.lib
    opencv_objdetect2411.lib
    opencv_photo2411.lib
    opencv_stitching2411.lib
    opencv_superres2411.lib
    opencv_ts2411.lib
    opencv_video2411.lib
    opencv_videostab2411.lib
    

That’s it, you now have a working OpenCV libraries in Visual Studio. You may want to save it as a template, so you don’t have to repeat it all over again.

Testing The Installation
Now for the fun part, let’s add a source code and compile it. We’ll make a simple image viewer using OpenCV. Add a new C++ file, name it anything. Type in the following code

// Simple image display using OpenCV

// Include opencv
#include <opencv2\opencv.hpp>
#include <opencv2\highgui\highgui.hpp>

void main()
{
	cv::Mat img = cv::imread("your image file here");// for example C:\\pictures\\image.jpg
	cv::imshow("image", img);
	cv::waitKey(); // so the program doesn't close directly.
}

Now build it, and see the image. If everything’s fine you should see an image being displayed.
Congratulations! You now have a working OpenCV installation in Visual Studio 2012. Now go and make something exciting.