A certification

Good news. I just received a certification from MongoDB University. There it is.

Cool! Right? I put in 7 weeks to complete this course. And here is the reference of the email:

Dear Tiger,

Congratulations! You have successfully completed M101JS: MongoDB for Node.js Developers with distinction. Your score puts you in the top 5% of all students who registered for the course. Great job!

WOW! Top 5%. Does it mean I am a top coder? I get myself calm and consider it a step to the upper level of my career life. Anyway, I’ll register the professional certification exam soon. Before that, I need to complete this blog.

OpenCV on node

Due to the new requirement of our project. (Yes, we did a reconstruction on our project.) We need to recognize the user’s face and crop it down to merge it into images sequence.
We’re working on Cocos Creator. Output target is Wechat game. We all know that Wechat works on mobile OS. Some of the native function and abilities are limited. Though the Wechat mini-app SDK provided some of the low-level api. But it’s doesn’t work when it comes to Wechat games.

So a better solution will be sending the image back to server, and let Master Bai,I mean, let the strong backend solve the problem. But before that, I need to walk through the path and make sure it works.

On Mac OS

Install opencv on mac os:

brew install opencv@2

After that, check the status of opencv by:

brew info opencv

If you find anything wrong with a red-cross mark, try to install it with brew.
Replace homebrew’s mirror(If it is unbearably slow) by:

export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles

or change it in :

echo 'export HOMEBREW_BOTTLE_DOMAIN=https://mirrors.tuna.tsinghua.edu.cn/homebrew-bottles' >> ~/.bash_profile
source ~/.bash_profile

After opencv installed, we need to config pkg_config by
export PKG_CONFIG_PATH=/path/to/opencv/lib/pkgconfig
locate into the path of your npm project.

npm i --save peterbraden/node-opencv
npm i --save opencv

After this, I think you already have a full config for opencv on Mac OS.
Here is how I test it:

var cv = require("opencv");
cv.readImage("./tiger2.png", function(err, im){
    im.detectObject(cv.FACE_CASCADE, {}, function(err, faces){
      for (var i=0;i<faces.length; i++){
        var x = faces[i]
        im.ellipse(x.x + x.width/2, x.y + x.height/2, x.width/2, x.height/2);

Just the sample code from official site.

Install opencv on CentOS:

I found CentOS is more friendly than Ubuntu. My feeling is base on what I need though.
Vultr have a very straightforward blog about this:

Master BAI did a more elegant version by GO after 12 hours since I made this test. Master is Master.

Decode QRCode by Typescript in Cocos Creator.

The key problem here is not the lib I need to use. After 10 minutes googling I am sure jsqr is the one I need. The problem is how to provide UTF8ClampedArray as a parameter to jsqr function.
Here is how I beat it:

        var self = this;
                count: 1, // 默认9
                sizeType: ['original', 'compressed'], 
                sourceType: ['album', 'camera'], 
                success: function (res) {
                    var url = res.tempFilePaths[0];

                        setTimeout(() => {
                        }, 1000);
        var gl = cc.game.canvas.getContext("webgl");
        var pixels = new    (gl.drawingBufferWidth * gl.drawingBufferHeight * 4);
                gl.readPixels(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight, gl.RGBA, gl.UNSIGNED_BYTE, pixels);
        var code = jsqr(pixels,cc.game.canvas.width,cc.game.canvas.height);
            this.label.string  = code.data;