It has been quite a while that my VOSM has NOT been updated. My bad for sure. But today, I have it updated, and VOSM-0.3.5 is released. Just refer to the following 3 pages on github:

We’ll still explain a bit on How to use VOSM in the following:

1. Building

1.1 Building Commands

Currently, there are 7 types of models to be built. Namely, there are 7 choices for the parameter “-t”:

  • SM
  • TM
  • AM
  • IA
  • FM
  • SMLTC
  • SMNDPROFILE
1
2
3
4
5
6
7
$ testsmbuilding -o "./output" -a "./annotations/training/" -i "./images/training/" -s "../VOSM/shapeinfo/IMM/ShapeInfo.txt" -d "IMM" -c 1 -t "SM" -l 4 -p 0.95
$ testsmbuilding -o "./output" -a "./annotations/training/" -i "./images/training/" -s "../VOSM/shapeinfo/IMM/ShapeInfo.txt" -d "IMM" -c 1 -t "TM" -l 4 -p 0.95
$ testsmbuilding -o "./output" -a "./annotations/training/" -i "./images/training/" -s "../VOSM/shapeinfo/IMM/ShapeInfo.txt" -d "IMM" -c 1 -t "AM" -l 4 -p 0.95
$ testsmbuilding -o "./output" -a "./annotations/training/" -i "./images/training/" -s "../VOSM/shapeinfo/IMM/ShapeInfo.txt" -d "IMM" -c 1 -t "IA" -l 4 -p 0.95
$ testsmbuilding -o "./output" -a "./annotations/training/" -i "./images/training/" -s "../VOSM/shapeinfo/IMM/ShapeInfo.txt" -d "IMM" -c 1 -t "FM" -l 4 -p 0.95
$ testsmbuilding -o "./output" -a "./annotations/training/" -i "./images/training/" -s "../VOSM/shapeinfo/IMM/ShapeInfo.txt" -d "IMM" -c 1 -t "SMLTC" -l 4 -p 0.95
$ testsmbuilding -o "./output" -a "./annotations/training/" -i "./images/training/" -s "../VOSM/shapeinfo/IMM/ShapeInfo.txt" -d "IMM" -c 1 -t "SMNDPROFILE" -l 4 -p 0.95

1.2 Output Folders

After these 7 commands, 9 folders will be generated:

  • Point2DDistributionModel
  • ShapeModel
  • TextureModel
  • AppearanceModel
  • AAMICIA
  • AFM
  • AXM
  • ASMLTCs
  • ASMNDProfiles

1.3 Output Images

Under folder TextureModel, 3 key images are generated:

Reference.jpg edges.jpg ellipses.jpg
Reference.jpg edges.jpg ellipses

Under folder AAMICIA, another 3 key images are generated:

m_IplImageTempFace.jpg m_IplImageTempFaceX.jpg m_IplImageTempFaceY.jpg
m_IplImageTempFace.jpg - same as Reference.jpg m_IplImageTempFaceX.jpg m_IplImageTempFaceY.jpg

2. Fitting

2.1 Fitting Commands

Current VOSM supports 5 fitting methods.

  • ASM_PROFILEND
  • ASM_LTC
  • AAM_BASIC
  • AAM_CMUICIA
  • AAM_IAIA
1
2
3
4
5
$ testsmfitting -o "./output/" -t "ASM_PROFILEND" -i "./images/testing/" -a "./annotations/testing/" -d "IMM" -s true -r true
$ testsmfitting -o "./output/" -t "ASM_LTC" -i "./images/testing/" -a "./annotations/testing/" -d "IMM" -s true -r true
$ testsmfitting -o "./output/" -t "AAM_BASIC" -i "./images/testing/" -a "./annotations/testing/" -d "IMM" -s true -r true
$ testsmfitting -o "./output/" -t "AAM_CMUICIA" -i "./images/testing/" -a "./annotations/testing/" -d "IMM" -s true -r true
$ testsmfitting -o "./output/" -t "AAM_IAIA" -i "./images/testing/" -a "./annotations/testing/" -d "IMM" -s true -r true

2.2 Fitting Results

Let’s just take ASM_PROFILEND as an example.

1
$ testsmfitting -o "./output/" -t "ASM_PROFILEND" -i "./images/testing/" -a "./annotations/testing/" -d "IMM" -s true -r true

All fitted images are generated under current folder, some are well fitted:

11-1m.jpg 33-4m.jpg 40-6m.jpg
11-1m.jpg 33-4m.jpg 40-6m

others are NOT well fitted:

12-3f.jpg 20-6m.jpg 23-4m.jpg
12-3f.jpg 20-6m.jpg 23-4m

2.3 Process of Fitting

The fitting process can also be recorded for each image if the parameter “-r” is enabled by -r true. Let’s take a look at what’s in folder 40-6m.

00.jpg 01.jpg 02.jpg
00.jpg 01.jpg 02.jpg
03.jpg 04.jpg 05.jpg
03.jpg 04.jpg 05.jpg
06.jpg 07.jpg 08.jpg
06.jpg 07.jpg 08.jpg
09.jpg 10.jpg 11.jpg
09.jpg 10.jpg 11.jpg
09.jpg 10.jpg 11.jpg
12.jpg 13.jpg 14.jpg
15.jpg 16.jpg
15.jpg 16.jpg

Clearly, the technology of pyramids is adopted during the fitting process.

To download videos from Youtube is sometimes required. Some Chrome plugins can be used to download Youtube videos, such as: Youtube Downloader. Other methods can also be found on various resources, such as: WikiHow.

In this blog, I’m going to cite (copy and paste) from WikiHow about How to download Youtube videos by using VLC.

STEP1: Copy Youtube URL

Find the Youtube video that you would like to download, and copy the Youtube URL.

STEP 2: Broadcast Youtube Video in VLC

Paste the URL under VLC Media Player->Media->Open Network Stream->Network Tab->Please enter a network URL:, and Play:

Video Broadcasting

STEP 3: Get the Real Location of Youtube Video

Then, copy the URL under Tools->Codec Information->Codec->Location:

Current Media Information

STEP 4: Save Video As

Finally, paste the URL in Chrome:

Save Video As

and Save video as….

1. IRC and Freenode

People have been using IRC for decades.

Freenode is an IRC network used to discuss peer-directed projects.

cited from Wikipedia.

It’s recommended to have some background about IRC and Freenode on Wikipedia:

2. Popular IRC Clients

Lots of IRC clients can be found on Google. Here, we just summarize some from IRC Wikipedia:

3. 7 Best IRC Clients for Linux

Please just refer to https://www.tecmint.com/best-irc-clients-for-linux/.

4. WeeChat in Linux

4.1 Installation

We can of course directly download the package from WeeChat Download, and have it installed from source. However, installing WeeChat from repository is recommended.

Step 1: Add the WeeChat repository

1
$ sudo sh -c 'echo "deb https://weechat.org/ubuntu $(lsb_release -cs) main" >> /etc/apt/sources.list.d/WeeChat.list'

Step 2: Add WeeChat repository key

1
$ sudo apt-key adv --keyserver keys.gnupg.net --recv-keys 11E9DE8848F2B65222AA75B8D1820DB22A11534E

Step 3: WeeChat Installation

1
2
$ sudo apt update
$ sudo apt install WeeChat

4.2 How to use WeeChat

Refer to WeeChat Official Documentation.

Step 1: Run WeeChat

1
$ weechat

will display:

WeeChat

And we FIRST type in /help

WeeChat

Step 2: Connect Freenode

1
/connect freenode

WeeChat

Step 3: Join a Channel

Here, we select channel OpenCV as an example:

1
/join #opencv

WeeChat

Step 4: Close a Channel

1
/close

5. Pidgin (Optional)

We’re NOT going to talk about it in this blog.

To DIY a home security camera is comparatively simple by using a low-cost embedded board with Linux installed. There are **ONLY 3 steps ** in total.

STEP1: Install MOTION from Repository

1
$ sudo apt install motion

STEP 2: start_motion_daemon=yes

1
$ sudo vim /etc/default/motion

Change start_motion_daemon from no to yes.

STEP 3: stream_localhost off

1
$ sudo vim /etc/motion/motion.conf

Change stream_localhost on to stream_localhost off.

STEP 4: Restart Motion Service

Run the following command:

1
$ sudo /etc/init.d/motion restart

STEP 5: Run Motion

1
$ sudo motion

STEP 6: Video Surveillance Remotely

Open up Chrome and type in the IP address:8081 to show the captured video at 1FPS. In my case, 192.168.0.86:8081, and the video effect is as:

Motion Video Surveillance

Finally, I’ve got some time to write something about PyTorch, a popular deep learning tool. We suppose you have had fundamental understanding of Anaconda Python, created Anaconda virtual environment (in my case, it’s named condaenv), and had PyTorch installed successfully under this Anaconda virtual environment condaenv.

Since I’m using Visual Studio Code to test my Python code (of course, you can use whichever coding tool you like), I suppose you’ve already had your own coding tool configured. Now, you are ready to go!

In my case, I’m giving a tutorial, instead of coding by myself. Therefore, Jupyter Notebook is selected as my presentation tool. So, I’ll demonstrate everything both in .py files, as well as .ipynb files. All codes can be found at Longer Vision PyTorch_Examples. However, ONLY Jupyter Notebook presentation is given in my blogs. Therefore, I suppose you’ve already successfully installed Jupyter Notebook, as well as any other required packages under your Anaconda virtual environment condaenv.

Now, let’s pop up Jupyter Notebook server.

Anaconda Python Virtual Environment

Clearly, Anaconda comes with the NEWEST version. So far, it is Python 3.6.4.

PART A: Hello PyTorch

Our very FIRST test code is of only 6 lines including an empty line:

After popping up Jupyter Notebook server, and click Run, you will see this view:

Jupyter Notebook Hello PyTorch

Clearly, the current torch is of version 0.3.1, and torchvision is of version 0.2.0.

PART B: Convolutional Neural Network in PyTorch

1. General Concepts

1) Online Resource

We are NOT going to discuss the background details of Convolutional Neural Network. A lot online frameworks/courses are available for you to catch up:

Several fabulous blogs are strongly recommended, including:

2) Architecture

One picture for all (cited from Convolutional Neural Network )

Typical Convolutional Neural Network Architecture

3) Back Propagation (BP)

The ONLY concept in CNN we want to emphasize here is Back Propagation, which has been widely used in traditional neural networks, which takes the solution similar to the final Fully Connected Layer of CNN. You are welcome to get some more details from https://brilliant.org/wiki/backpropagation/.

Pre-defined Variables

Training Database
  • $X={(\vec{x_1},\vec{y_1}),(\vec{x_2},\vec{y_2}),…,(\vec{x_N},\vec{y_N})}$: the training dataset $X$ is composed of $N$ pairs of training samples, where $(\vec{x_i},\vec{y_i}),1 \le i \le N$
  • $(\vec{x_i},\vec{y_i}),1 \le i \le N$: the $i$th training sample pair
  • $\vec{x_i}$: the $i$th input vector (can be an original image, can also be a vector of extracted features, etc.)
  • $\vec{y_i}$: the $i$th desired output vector (can be a one-hot vector, can also be a scalar, which is a 1-element vector)
  • $\hat{\vec{y_i} }$: the $i$th output vector from the nerual network by using the $i$th input vector $\vec{x_i}$
  • $N$: size of dataset, namely, how many training samples
  • $w_{ij}^k$: in the neural network’s architecture, at level $k$, the weight of the node connecting the $i$th input and the $j$th output
  • $\theta$: a generalized denotion for any parameter inside the neural networks, which can be looked on as any element from a set of $w_{ij}^k$.
Evaluation Function
  • Mean squared error (MSE): $$E(X, \theta) = \frac{1}{2N} \sum_{i=1}^N \left(||\hat{\vec{y_i} } - \vec{y_i}||\right)^2$$
  • Cross entropy: $$E(X, prob) = - \frac{1}{N} \sum_{i=1}^N log_2\left({prob(\vec{y_i})}\right)$$

Particularly, for binary classification, logistic regression is often adopted. A logistic function is defined as:

$$f(x)=\frac{1}{(1+e^{-x})}$$

In such a case, the loss function can easily be deducted as:

$$E(X,W) = - \frac{1}{N} \sum_{i=1}^N [y_i log({\hat{y_i} })+(1-y_i)log(1-\hat{y_i})]$$

where

$$y_i=0/1$$

$$\hat{y_i} \equiv g(\vec{w} \cdot \vec{x_i}) = \frac{1}{(1+e^{-\vec{w} \cdot \vec{x_i} })}$$

Some PyTorch explaination can be found at torch.nn.CrossEntropyLoss.

BP Deduction Conclusions

Only MSE is considered here (Please refer to https://brilliant.org/wiki/backpropagation/):

$$
\frac {\partial {E(X,\theta)} } {\partial w_{ij}^k} = \frac {1}{N} \sum_{d=1}^N \frac {\partial}{\partial w_{ij}^k} \Big( {\frac{1}{2} (\vec{y_d}-y_d)^2 } \Big) = \frac{1}{N} \sum_{d=1}^N {\frac{\partial E_d}{\partial w_{ij}^k} }
$$

The updating weights is also determined as:

$$
\Delta w_{ij}^k = - \alpha \frac {\partial {E(X,\theta)} } {\partial w_{ij}^k}
$$

2. PyTorch Implementation of Canonical CNN

Hi, today, I’m going to revisit a very old topic, Setup Repeater Bridge Using A dd-wrt Router. This reminds me of my FIRST startup Misc Vision that used to resell Foscam home security IP cameras. That is a long story. Anyway, this blog is going to heavily cite the contents on this page.

PART A: Flash A Supported Router with DD-WRT Firmware

Before we start to tackle the problem, the open source firmware DD-WRT is strongly recommended to flash your router.

1. DD-WRT and OpenWRT

Two widely used open source router firmware have been published online for quite a bit of time: DD-WRT, OpenWRT In fact, each of these two are OK for router firmware flashing.

2. DD-WRT Supported Routers

To check if your router is supported by DD-WRT, you need to check this page.

3. DD-WRT SL-R7202

In my case, I got a lot of such routers in hand and am selling them on Craigslist (if anybody is interested in it, please let me know). You can also find some either continued or discontinued such products on the market, such as Gearbest.

DD-WRT SL-R7202 looks good:

DD-WRT SL-R7202 Top

DD-WRT SL-R7202 Size

In one word, find some DD-WRT supported router, and have it successfully flashed FIRST. As a lazy man, I’m NOT going to flash anything but just use a router coming with an existing DD-WRT firmware, namely, DD-WRT SL-R7202.

PART B: The Problem

The problem that we are going to deal with is how to connect multiple routers, so that the Internet range can be expanded. For routers with dd-wrt firmware, there are mulitple ways to connect routers, please refer to https://www.dd-wrt.com/wiki/index.php/Linking_Routers.

1. Linking Routers

In the following, most contents are CITED directly from Linking Routers and its extended webpages.

  • Access Point / Switch - Extend the Wireless access area using more routers, with WIRED connections between routers, or turn a WIRED port on an existing network into a Wireless Access Point. All computers will be on the same network segment, and will be able to see one another in Windows Network. This works with all devices with LAN ports, and does not require dd-wrt to be installed. “

    • Wireless Access Point - Extend Wi-Fi & LAN (Requires physical(just WIRED) ethernet connection between routers)
    • Switch - Similar config as WAP, but radio disabled (accepts only WIRED connections)

DD-WRT Access Point Mode

  • Repeater / Repeater Bridge - Extend the Wireless access area using a second router WIRELESSLY connected to the primary. The secondary router must have dd-wrt installed; the primary does not need dd-wrt.

    • Repeater Bridge - A wireless repeater with DHCP & NAT disabled, clients on same subnet as host AP (primary router). That is, all computers can see one another in Windows Network.
    • Repeater - A wireless repeater with DHCP & NAT enabled, clients on different subnet from host AP (primary router). Computers connected to one router can not see computers connected to other routers in Windows Network.
    • Universal Wireless Repeater - Uses a program/script called AutoAP to keep a connection to the nearest/best host AP.

DD-WRT Repeater Bridge Mode

  • Client / Client Bridge - Connect two wired networks using a WiFi link (WIRELESS connection between two routers). The secondary router must have dd-wrt installed; the primary router does not need to have dd-wrt.

    • Client Bridged - Join two wired networks by two Wireless routers building a bridge. All computers can see one another in Windows Network.
    • Client Mode - Join two wired networks by two Wireless routers (unbridged). Computers on one wired network can not see computers on other wired network in Windows Network.

DD-WRT Client Bridge Mode

  • WDS - Extend the Wireless access area using more routers connected WIRELESSLY. WDS is a mesh network. Routers must almost always have the SAME chipset type for WDS to work, and any non dd-wrt routers must be WDS compatible. Using identical routers is best, but not always necessary if all devices have the same chipset types. (All Broadcom or all Atheros etc)

  • OLSR - Extend the Wireless access area using more routers. Extra routers do not need any wired connections to each other. Use several ISP (Internet) connections. OLSR is a mesh network.

2. Down-to-earth Case

In my case, my laptop and some of my IoT devices can be easily connected to the ShawCable Modem/Router combo, which is on the 2nd floor in my living room and directly connected to the Internet. However, my R&D office is located in my garage on the 1st floor, where dd-wrt router is put in. In such a case, my dd-wrt router must be connected to my ShawCable Modem/Router WIRELESSLY.

Due to the reason explained in the section Difference between Client Bridge and Repeater Bridge. A standard wireless bridge (Client Bridge) connects wired clients to a secondary router as if they were connected to your main router with a cable. Secondary clients share the bandwidth of a wireless connection back to your main router. Of course, you can still connect clients to your main router using either a cable connection or a wireless connection.

The limitation with standard bridging is that it only allows WIRED clients to connect to your secondary router. WIRELESS clients cannot connect to your secondary router configured as a standard bridge. Repeater Bridge allows both WIRELESS AND WIRED clients to connect to a the Repeater Bridge router, and through that device WIRELESSLY to a primary router. You can still use this mode if you only need to bridge wired clients; the extra wireless repeater capability comes along for free; however, you are not required to use it.

Therefore, we select Repeater Bridge as our solution. Here, DD-WRT SL-R7202 is selected as the Repeater Bridge. The difficulty is how to setup DD-WRT SL-R7202 to make it work as a wireless Repeater Bridge?

PART C: About Firmware (Optional)

1. Do We Need Firmware Upgrading?

Actually, before I come to this step, I’ve already:

It seems to me that a firmware upgrading is a must before we setup the Wireless Repeater Bridge Mode. But, How?

2. Reset to Factory Defaults on DD-WRT Router (The 2nd Router)

First of all, we need to reset DD-WRT. There is a black button on my DD-WRT SL-R7202, as shown:

Reset Button at DD-WRT's Back

In fact, how to reset DD-WRT needs to be paid attention to. > Hold the reset button until lights flash (10-30sec) or 30-30-30 if appropriate for your router. (DO NOT 30-30-30 ARM routers.)

3. Visit http://192.168.1.1:

After successfully reset DD-WRT router to factory default, connect it with your host computer via a WIRED cable, for better stablity. Then, we change our network connection from our FIRST router to SECOND router: dd-wrt router. Afterwards, let’s visit http://192.168.1.1.

  • NOTE: My host computer’s IP address on the FIRST router, namely, ShawCable Modem/Router is staticly set as 192.168.0.8 (which is able to connect to the Internet). After I switch to the Wifi dd-wrt, my host’s IP is DHCP allocated to 192.168.1.103. The gateway on ShawCable is 192.168.0.1, which is different from the gateway on dd-wrt 192.168.1.1 by default.

1) FIRST Page

DD-WRT home page looks like:

DD-WRT First Login

And it’s suggested we input a new router username root and password admin. After the button Change Password is clicked, we are entering the very first page of DD-WRT Web GUI.

DD-WRT First Page

  • We can easily tell the firmware’s info on the top right corner.
1
2
3
Firmware: DD-WRT v24-sp2 (10/10/09) std
Time: 00:01:13 up 1 min, load average: 0.12, 0.04, 0.00
WAN IP: 0.0.0.0
  • And, we can also easily tell from the bottom of this page that for now, only 1 DHCP client is connected to this router, which is just our host computer: jiapei-GT72-6QE.

2) System Info on Status Page

DD-WRT Status page tells a lot about what’s in this router:

DD-WRT Status - Before Upgrading

Clearly, our router model is Buffalo WHR-G300N, and our firmware build version is 13064.

3) Upgradable?

We then visit https://www.dd-wrt.com/site/support/router-database, and input WHR-G300N, two routers will be listed as:

DD-WRT WHR-G300N

By click the FIRST one, namely v1, we get:

DD-WRT WHR-G300N v1: from 13064 to 14896

Clearly, we should be able to upgrade from our current firmware version 13064 to the newer one 14896.

With the existing firmware version 13064 installed on the router SL-R7202, we can directly upgrade the firmware through web flash by downloading the firmware WHR-G300N-webflash.bin, but ignoring downloading all TFTP and openvpn files.

4) Firmware Upgrading

Just click Administration -> Firmware Upgrade, and then choose WHR-G300N-webflash.bin.

DD-WRT Administration - Firmware Upgrade

After clicking Choose file, the system is automatically upgraded after several minutes.

NOTE: Do NOT touch anything during the upgrading process.

DD-WRT Upgrade Successful

After firmware upgrading, we can easily tell some difference: From Setup Page, on the left-top corner, we can see the builder version is now 14896. And from the right-top corner, the current firmware info is:

1
2
3
Firmware: DD-WRT v24-sp2 (08/07/10) std
Time: 00:08:20 up 8 min, load average: 0.00, 0.02, 0.00
WAN IP: 0.0.0.0

DD-WRT Setup - Basic Setup

From the Status Page, we can doublecheck the firmware version is now 14896.

DD-WRT Status - After Upgrading

5) Firmware Upgrading is Problematic !

However, upgrading the firmware version from 13064 to the newer one 14896 is problematic, please refer to https://jgiam.com/2012/07/06/setting-up-a-repeater-bridge-with-dd-wrt-and-d-link-dir-600. After carefully reading this article, and due to my practical try later on, I summarized the conclusion here first:

  • NOTE:
    • KEEP using firmware version 13064, instead of 14896
    • NEVER adding the Virtual Interfaces

PART D: Wireless Repeater Bridge (Same Subset)

1. Wireless -> Basic Settings

We modify the parameters accordingly (Cited from the blog Setting up a repeater bridge with DD-WRT and D-Link DIR-600 ):

  • Physical Interface Section
    • Wireless Mode: Repeater Bridge
    • Wireless Network Mode: Must Be Exactly The Same As Primary Router
    • Wireless Network Name (SSID): Must Be Exactly The Same As Primary Router. Be Careful: DD-WRT is ONLY a 2.4G router. If your primary router has two bands, namely, 2.4G and 5G, make sure you connect to the 2.4G network.
    • Wireless Channel: Must Be Exactly The Same As Primary Router
    • Channel Width: Must Be Exactly The Same As Primary Router
    • Wireless SSID Broadcast: Enabled
    • Network Configuration: Bridged

Then, click Save without Apply, we get:

DD-WRT Wireless - Basic Settings

2. Wireless -> Wireless Security

  • Physical Interface section
    • Security Mode: Must Be WPA2 Personal, and The Primary Router Must Be Exactly The Same.
    • WPA Algorithms: Must Be AES, and The Primary Router Must Be Exactly The Same.
    • WPA Shared Key: Must Be Exactly The Same As Primary Router
    • Key Renewal Interval (in seconds): Leave as it is, normally, 3600.

Then, click Save without Apply, we get:

DD-WRT Wireless - Wireless Security

3. Setup -> Basic Setup

  • WAN Connection Type Section
    • Connection Type: Disabled
    • STP: Disabled
  • Optional Settings
    • Router Name: DD-WRT, just let it be
  • Router IP
    • IP Address: 192.168.0.2 (in my case, my Primary Router IP is 192.168.0.1, and 192.168.0.2 has NOT been used yet.)
    • Subnet Mask: 255.255.255.0
    • Gateway: 192.168.0.1 (Must Be Primary Router IP)
    • Local DNS: 192.168.0.1 (Must Be Primary Router IP)
  • WAN Port
    • Assign WAN Port to Switch: tick
  • Time Settings
    • Time Zone: set correspondingly

Then, click Save without Apply, we get:

DD-WRT Setup - Basic Setup

4. Setup -> Advanced Routing

  • Operating Mode Section
    • Operating Mode: Router

Then, click Save without Apply, we get:

DD-WRT Setup - Advanced Routing

5. Services -> Services

  • DNSMasq Section
    • DNSMasq: Diable
  • Secure Shell Section
    • SSHd: Enable
  • Telnet Section
    • Telnet: Enable

Then, click Save without Apply, we get:

DD-WRT Services - Services

6. Security -> Firewall

Note: Process in Sequence.

  • Block WAN Requests
    • Block Anonymous WAN Requests (Ping): untick
    • Filter Multicast: tick
    • Filter WAN NAT Redirection: untick
    • Filter IDENT (Port 113): untick
  • Firewall Protection
    • SPI Firewall: Disable

Then, click Save without Apply, we get:

DD-WRT Security - Firewall

7. Administration Management

  • Remote Access Section
    • Web GUI Management: Enable
    • SSH Management: Enable
    • Telnet Remote Port: Enable
    • Allow Any Remote IP: Enable

Then, click Save without Apply, we get:

DD-WRT Administration - Management

Now, it’s the time to Apply Settings

DD-WRT Administration - Management - Apply Settings

And finally, click Reboot Router

DD-WRT Administration - Management - Reboot Router

PART E: Doublechek Repeater Bridge

1. Ping

Let’s see the ping results directly:

1) PC Wired Connecting to DD-WRT (Router 2)

DD-WRT Wired Connection Between PC and Router 2, Namely, DD-WRT

2) PC Wirelessly Connecting to Router 1 - 5G

DD-WRT Wifi Connection Between PC and Primary Router 1's 5G Network

3) PC Wirelessly Connecting to Router 1 - 2.4G

DD-WRT Wifi Connection Between PC and Primary Router 1's 2.4G Network

2. Visit http://192.168.0.1 and http://192.168.0.2

Most of the time, in order to get the fastest Internet speed, I use Primary Router 1’s 5G network. Therefore, for my final demonstration, my PC is wirelessly connected to the 5G network. And, I can successfully visit http://192.168.0.1 and http://192.168.0.2.

1) http://192.168.0.1

http://192.168.0.1

2) http://192.168.0.2

http://192.168.0.2

Today, we are going to install a runnable Linux OS Armbian and then flash the most recent supported Linux Kernel onto an Orange Pi Plus 2, which adopts AllWinner H3 as its CPU. The board looks like (cited from Orange Pi Plus 2 ):

Orange Pi Plus 2

Similar to our previous blog Install Armbian Debian Server onto NanoPi NEO, to build the Mainline Linux for Orange Pi Plus 2, we use the Embedded Linux management open source Armbian. However, this time, we’ll have the most recently supported Linux Kernel updated finally.

PART A: Install Ubuntu Desktop Built By Armbian onto Orange Pi Plus 2

1. Download Armbian Ubuntu Desktop for Orange Pi Plus 2

We FIRST go visiting the website https://www.armbian.com/orange-pi-plus-2/ and click Ubuntu desktop - legacy kernel icon, a file named Armbian_5.38_Orangepiplus_Ubuntu_xenial_default_3.4.113_desktop.7z will be automatically downloaded.

Then, we extract this .7z file by

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$ 7z x Armbian_5.38_Orangepiplus_Ubuntu_xenial_default_3.4.113_desktop.7z

7-Zip (A) [64] 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18
p7zip Version 9.20 (locale=en_CA.UTF-8,Utf16=on,HugeFiles=on,8 CPUs)

Processing archive: Armbian_5.38_Orangepiplus_Ubuntu_xenial_default_3.4.113_desktop.7z

Extracting Armbian_5.38_Orangepiplus_Ubuntu_xenial_default_3.4.113_desktop.img
Extracting armbian.txt
Extracting armbian.txt.asc
Extracting Armbian_5.38_Orangepiplus_Ubuntu_xenial_default_3.4.113_desktop.img.asc
Extracting sha256sum.sha

Everything is Ok

Files: 5
Size: 3061862273
Compressed: 606477386

2. Install Armbian Ubuntu Desktop for Orange Pi Plus 2

After the extracted image file is prepared, it’s the time to install the Armbian Ubuntu Desktop onto our TF card. We FIRST format the TF card:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$ sudo mkfs.ext4 /dev/mmcblk0 
[sudo] password for jiapei:
mke2fs 1.42.13 (17-May-2015)
Found a dos partition table in /dev/mmcblk0
Proceed anyway? (y,n) y
Discarding device blocks: done
Creating filesystem with 7791744 4k blocks and 1949696 inodes
Filesystem UUID: 8873533f-4a66-4e8c-8633-844eaa90116d
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208,
4096000

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done
Writing superblocks and filesystem accounting information: done

Afterwards, use dd to install the downloaded Armbian Ubuntu Desktop image.

1
2
3
4
5
$ sudo dd bs=4M if=Armbian_5.38_Orangepiplus_Ubuntu_xenial_default_3.4.113_desktop.img of=/dev/mmcblk0 conv=fsync
[sudo] password for jiapei:
730+0 records in
730+0 records out
3061841920 bytes (3.1 GB, 2.9 GiB) copied, 381.133 s, 8.0 MB/s

3. Boot Into Orange Pi Plus 2

We now unplug the TF card from the host and put it into the Orange Pi Plus 2 board, Armbian Ubuntu Desktop boots successfully. Make sure the username and password are respectively: root and 1234. And you will notice that

1
2
3
4
5
6
You are required to change your password immediately (root enforced)
Changing password for root.
(current) UNIX password:
Enter new UNIX password:
Retype new UNIX password:
...

And, for the FIRST boot, we’ll be asked to create a NEW user besides root:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
Creating a new user account. Press <Ctrl-C> to abort
Desktop enironment will not be enabled if you abort the new user creation

Please provide a username (eg. your forename): orangepiplus2
Trying to add user orangepiplus2
Adding user 'orangepiplus2' ...
Adding new group 'orangepiplus2' (1000) ...
Adding new user 'orangepiplus2' (1000) with group 'orangepiplus2' ...
Creating home directory '/home/orangepiplus2' ...
Copying files from '/etc/ske1' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for orangepiplus2
Eter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] Y
...

Then, Orange Pi Plus 2 will boot into GUI as follows.

Armbian Ubuntu Desktop Overview

We are now able to see the kernel version is of 3.4.113, which is a very old Linux Kernel.

Armbian Kernel Version

We then update/upgrade all upgradable packages, and have the system rebooted.

Armbian Apt Update

Armbian Apt Upgrade

After finishing the upgrading, Ubuntu has successfully upgraded from 16.04.3 to 16.04.4, but Linux Kernel is still of version 3.4.113.

Armbian All Upgraded

PART B: Build The Newest Armbian U-Boot and Linux Kernel for Orange Pi Plus 2

As shown in PART A, the current Linux Kernel on our Orange Pi Plus 2 is of an old version 3.4.113. Are we able to upgrade the Linux Kernel to the most recent one? The ANSWER is of course YES.

1. Download Armbian Source Code

1
$ git clone git@github.com:armbian/build.git armbian

2. Test Compiling

We now try to compile Armbian for our very FIRST attempt. This will help us to download a lot required packages, including all Linaro toolchains, U-Boot, etc., and save those packages under folder cache,

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
$ cd ./armbian
$ ./compile.sh
[ o.k. ] Using config file [ config-default.conf ]
[ warn ] This script requires root privileges, trying to use sudo
[sudo] password for jiapei:
[ o.k. ] Using config file [ config-default.conf ]
[ o.k. ] This script will try to update
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Already on 'master'
Your branch is up-to-date with 'origin/master'.
[ o.k. ] Preparing [ host ]
[ o.k. ] Build host OS release [ xenial ]
[ o.k. ] Syncing clock [ host ]
[ .... ] Downloading [ gcc-linaro-arm-linux-gnueabihf-4.8-2014.04_linux ]
######################################################################## 100.0%
######################################################################## 100.0%
[ .... ] Verifying
gpg: keyring `/home/jiapei/Downloads/OperatingSystems/linux/distros/armbian/armbian/cache/.gpg/pubring.gpg' created
gpg: /home/jiapei/Downloads/OperatingSystems/linux/distros/armbian/armbian/cache/.gpg/trustdb.gpg: trustdb created
gpg: error reading key: public key not found
gpg: keyring `/home/jiapei/Downloads/OperatingSystems/linux/distros/armbian/armbian/cache/.gpg/secring.gpg' created
gpg: requesting key 8F427EAF from hkp server keyserver.ubuntu.com
gpg: key 8F427EAF: public key "Linaro Toolchain Builder <michael.hope+cbuild@linaro.org>" imported
gpg: Total number processed: 1
gpg: imported: 1 (RSA: 1)
gpg: assuming signed data in `gcc-linaro-arm-linux-gnueabihf-4.8-2014.04_linux.tar.xz'
gpg: Signature made Wed 16 Apr 2014 11:29:14 AM PDT using RSA key ID 8F427EAF
gpg: Good signature from "Linaro Toolchain Builder <michael.hope+cbuild@linaro.org>"
[ .... ] Extracting
[ o.k. ] Download complete
[ .... ] Downloading [ gcc-linaro-4.9.4-2017.01-x86_64_aarch64-linux-gnu ]
######################################################################## 100.0%
######################################################################## 100.0%
[ .... ] Verifying
[ .... ] Extracting
[ o.k. ] Download complete
[ .... ] Downloading [ gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabi ]
######################################################################## 100.0%
######################################################################## 100.0%
[ .... ] Verifying
[ .... ] Extracting
[ o.k. ] Download complete
[ .... ] Downloading [ gcc-linaro-4.9.4-2017.01-x86_64_arm-linux-gnueabihf ]
######################################################################## 100.0%
######################################################################## 100.0%
[ .... ] Verifying
[ .... ] Extracting
[ o.k. ] Download complete
[ .... ] Downloading [ gcc-linaro-5.5.0-2017.10-x86_64_aarch64-linux-gnu ]
######################################################################## 100.0%
######################################################################## 100.0%
[ .... ] Verifying
[ .... ] Extracting
[ o.k. ] Download complete
[ .... ] Downloading [ gcc-linaro-5.5.0-2017.10-x86_64_arm-linux-gnueabi ]
######################################################################## 100.0%
######################################################################## 100.0%
[ .... ] Verifying
[ .... ] Extracting
[ o.k. ] Download complete
[ .... ] Downloading [ gcc-linaro-5.5.0-2017.10-x86_64_arm-linux-gnueabihf ]
######################################################################## 100.0%
######################################################################## 100.0%
[ .... ] Verifying
[ .... ] Extracting
[ o.k. ] Download complete
[ .... ] Downloading [ gcc-linaro-6.4.1-2017.11-x86_64_arm-linux-gnueabihf ]
######################################################################## 100.0%
######################################################################## 100.0%
[ .... ] Verifying
[ .... ] Extracting
[ o.k. ] Download complete
[ .... ] Downloading [ gcc-linaro-6.4.1-2017.11-x86_64_aarch64-linux-gnu ]
######################################################################## 100.0%
######################################################################## 100.0%
[ .... ] Verifying
[ .... ] Extracting
[ o.k. ] Download complete
[ .... ] Downloading [ gcc-linaro-7.2.1-2017.11-x86_64_aarch64-linux-gnu ]
######################################################################## 100.0%
######################################################################## 100.0%
[ .... ] Verifying
[ .... ] Extracting
[ o.k. ] Download complete
[ .... ] Downloading [ gcc-linaro-7.2.1-2017.11-x86_64_arm-linux-gnueabihf ]
######################################################################## 100.0%
######################################################################## 100.0%
[ .... ] Verifying
[ .... ] Extracting
[ o.k. ] Download complete

Then, a canonical GUI will jump out onto the screen for you to make selections:

U-boot and kernel packages

Show a kernel configuration menu before compilation

Officially supported boards

Clearly, our board Orange Pi Plus 2 is NOT in the list. Therefore, we select Cancel here for now, and some ERROR messages will be generated as follows.

1
2
3
[ error ] ERROR in function source [ main.sh:198 ]
[ error ] No kernel branch selected
[ o.k. ] Process terminated

3. Prepare The Board Configuration File

We doublecheck the officially supported boards:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
$ cd ./config/boards
$ ls -1 *orangepi*
orangepi2.conf
orangepi2g-iot.csc
orangepi.eos
orangepilite.conf
orangepimini.eos
orangepione.conf
orangepipc2.conf
orangepipc.conf
orangepipcplus.conf
orangepiplus2e.conf
orangepiplus.conf
orangepiprime.conf
orangepi-r1.conf
orangepiwin.conf
orangepizero.conf
orangepizeroplus2-h3.conf
orangepizeroplus2-h5.conf
orangepizeroplus.conf

As we can see, it is certain that our board Orange Pi Plus 2 is NOT officially supported. Due to the trivial difference between Orange Pi Plus 2 and Orange Pi Plus 2e, we configure our Orange Pi Plus 2 board as a Orange Pi Plus 2e board by:

1
$ cp orangepiplus2e.conf orangepiplus2.conf

Afterwards, we modify the file content in orangepiplus2.conf manually:

1
$ vim orangepiplus2.conf

and, the file content is correspondingly modified to:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# H3 quad core 2GB RAM WiFi eMMC
BOARD_NAME="Orange Pi+ 2"
BOARDFAMILY="sun8i"
BOOTCONFIG="orangepi_plus2_defconfig"
#
MODULES="8189fs #w1-sunxi #w1-gpio #w1-therm #gc2035 #vfe_v4l2 #sunxi-cir"
MODULES_NEXT="8189fs"
CPUMIN="408000"
CPUMAX="1296000"
#
KERNEL_TARGET="default,next,dev"
CLI_TARGET="stretch,xenial:next"
DESKTOP_TARGET="xenial:default"
#
CLI_BETA_TARGET=""
DESKTOP_BETA_TARGET=""
#
RECOMMENDED="Ubuntu_xenial_default_desktop:90,Debian_stretch_next:75"
#
BOARDRATING=""
CHIP="http://docs.armbian.com/Hardware_Allwinner-H3/"
HARDWARE="http://www.orangepi.org/orangepiplus2/"
FORUMS="http://forum.armbian.com/index.php/forum/13-allwinner-h3/"
BUY="http://s.click.aliexpress.com/e/VbA6AEq"

4. Prepare Board Configuration File for U-Boot

Then, we recompile armbian with some particular options (Please refer to Armbian Build Options for parameter details):

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
$ cd ../../
$ ./compile.sh BOARD="orangepiplus2" BRANCH="next" KERNEL_ONLY="yes" KERNEL_CONFIGURE="no"
[ o.k. ] Using config file [ config-default.conf ]
[ warn ] This script requires root privileges, trying to use sudo
[sudo] password for jiapei:
[ o.k. ] Using config file [ config-default.conf ]
[ o.k. ] This script will try to update
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Already on 'master'
Your branch is up-to-date with 'origin/master'.
[ o.k. ] Command line: setting BOARD to [ orangepiplus2 ]
[ o.k. ] Command line: setting BRANCH to [ next ]
[ o.k. ] Command line: setting KERNEL_ONLY to [ no ]
[ o.k. ] Command line: setting KERNEL_CONFIGURE to [ no ]
[ o.k. ] Preparing [ host ]
[ o.k. ] Build host OS release [ xenial ]
[ o.k. ] Syncing clock [ host ]

Again, the canonical GUI will jump out onto the screen for you to make selections, here we select Ubuntu Xenial 16.04 LTS and Image with console interface (server) respectively.

Target OS release

Target image type

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
[ o.k. ] Downloading sources 
[ o.k. ] Checking git sources [ u-boot v2017.11 ]
[ .... ] Creating local copy
[ .... ] Fetching updates
remote: Counting objects: 13853, done.
remote: Compressing objects: 100% (12500/12500), done.
remote: Total 13853 (delta 2493), reused 5244 (delta 1104)
Receiving objects: 100% (13853/13853), 17.27 MiB | 1.00 MiB/s, done.
Resolving deltas: 100% (2493/2493), done.
From git://git.denx.de/u-boot
* tag v2017.11 -> FETCH_HEAD
[ .... ] Checking out
[ o.k. ] Checking git sources [ linux-mainline linux-4.14.y ]
[ .... ] Creating local copy
[ .... ] Fetching updates
remote: Counting objects: 65193, done.
remote: Compressing objects: 100% (60945/60945), done.
remote: Total 65193 (delta 5919), reused 26531 (delta 3272)
Receiving objects: 100% (65193/65193), 172.40 MiB | 3.26 MiB/s, done.
Resolving deltas: 100% (5919/5919), done.
From git://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable
* branch linux-4.14.y -> FETCH_HEAD
* [new branch] linux-4.14.y -> origin/linux-4.14.y
[ .... ] Checking out
[ o.k. ] Checking git sources [ sunxi-tools master ]
[ .... ] Creating local copy
[ .... ] Fetching updates
remote: Counting objects: 83, done.
remote: Compressing objects: 100% (78/78), done.
remote: Total 83 (delta 13), reused 33 (delta 4), pack-reused 0
Unpacking objects: 100% (83/83), done.
From https://github.com/linux-sunxi/sunxi-tools
* branch master -> FETCH_HEAD
* [new branch] master -> origin/master
[ .... ] Checking out
[ o.k. ] Checking git sources [ rkbin-tools master ]
[ .... ] Creating local copy
[ .... ] Fetching updates
remote: Counting objects: 232, done.
remote: Compressing objects: 100% (182/182), done.
remote: Total 232 (delta 57), reused 209 (delta 50), pack-reused 0
Receiving objects: 100% (232/232), 22.60 MiB | 8.32 MiB/s, done.
Resolving deltas: 100% (57/57), done.
From https://github.com/rockchip-linux/rkbin
* branch master -> FETCH_HEAD
* [new branch] master -> origin/master
[ .... ] Checking out
[ o.k. ] Checking git sources [ marvell-tools A3700_utils-armada-17.10 ]
[ .... ] Creating local copy
[ .... ] Fetching updates
remote: Counting objects: 294, done.
remote: Compressing objects: 100% (150/150), done.
remote: Total 294 (delta 151), reused 229 (delta 140), pack-reused 0
Receiving objects: 100% (294/294), 5.80 MiB | 4.40 MiB/s, done.
Resolving deltas: 100% (151/151), done.
From https://github.com/MarvellEmbeddedProcessors/A3700-utils-marvell
* branch A3700_utils-armada-17.10 -> FETCH_HEAD
* [new branch] A3700_utils-armada-17.10 -> origin/A3700_utils-armada-17.10
[ .... ] Checking out
[ o.k. ] Checking git sources [ odroidc2-blobs master ]
[ .... ] Creating local copy
[ .... ] Fetching updates
remote: Counting objects: 13, done.
remote: Compressing objects: 100% (13/13), done.
remote: Total 13 (delta 0), reused 11 (delta 0), pack-reused 0
Unpacking objects: 100% (13/13), done.
From https://github.com/armbian/odroidc2-blobs
* branch master -> FETCH_HEAD
* [new branch] master -> origin/master
[ .... ] Checking out
[ o.k. ] Compiling [ sunxi-tools ]
Setting version information: 5c19710

[ o.k. ] Installing [ rkbin-tools ]
[ o.k. ] Cleaning output/debs for [ orangepiplus2 next ]
[ o.k. ] Cleaning [ u-boot/v2017.11 ]
[ o.k. ] Compiling u-boot [ 2017.11 ]
[ o.k. ] Compiler version [ arm-linux-gnueabihf-gcc 7.2.1 ]
[ .... ] Checking out sources
[ o.k. ] Cleaning [ u-boot/v2017.11 ]
[ o.k. ] Started patching process for [ u-boot sunxi-orangepiplus2-next ]
[ o.k. ] Looking for user patches in [ userpatches/u-boot/u-boot-sunxi ]
[ o.k. ] * [l][c] 0020-sunxi-call-fdt_fixup_ethernet-again-to-set-macaddr-f.patch
[ o.k. ] * [l][c] 4kfix-limit-screen-to-full-hd.patch
[ o.k. ] * [l][c] Add-A20-Olimex-SOM204-EVB-board.patch
[ o.k. ] * [l][c] add-a20-olinuxino-micro-emmc-support.patch
[ o.k. ] * [l][c] add-a20-optional-eMMC.patch
[ o.k. ] * [l][c] add-bananapi-bpi-m2-zero.patch
[ o.k. ] * [l][c] add-beelink-x2.patch
[ o.k. ] * [l][c] add-nanopi-air-emmc.patch
[ o.k. ] * [l][c] add-nanopi-duo.patch
[ o.k. ] * [l][c] add-nanopi-m1-plus2-emmc.patch
[ o.k. ] * [l][c] add-nanopineoplus2.patch
[ o.k. ] * [l][c] add-orangepi-plus2-emmc.patch
[ o.k. ] * [l][c] add-orangepi-zeroplus.patch
[ o.k. ] * [l][c] add-orangepi-zeroplus2_h3.patch
[ o.k. ] * [l][c] add-sunvell-r69.patch
[ o.k. ] * [l][c] add-tritium.patch
[ o.k. ] * [l][c] add_emmc_olinuxino_a64.patch
[ o.k. ] * [l][c] add_emmc_orangepiwin.patch
[ o.k. ] * [l][c] adjust-default-dram-clockspeeds.patch
[ o.k. ] * [l][c] adjust-small-boards-cpufreq.patch
[ o.k. ] * [l][c] enable-DT-overlays-support.patch
[ o.k. ] * [l][c] enable-autoboot-keyed.patch
[ o.k. ] * [l][c] fdt-setprop-fix-unaligned-access.patch
[ o.k. ] * [l][c] fix-sdcard-detect-bpi-m2z.patch
[ o.k. ] * [l][c] fix-sunxi-gpio-driver.patch
[ o.k. ] * [l][c] fix-usb1-vbus-opiwin.patch
[ o.k. ] * [l][c] h3-Fix-PLL1-setup-to-never-use-dividers.patch
[ o.k. ] * [l][c] h3-enable-power-led.patch
[ o.k. ] * [l][c] h3-set-safe-axi_apb-clock-dividers.patch
[ o.k. ] * [l][c] lower-default-DRAM-freq-A64-H5.patch
[ o.k. ] * [l][c] lower-default-cpufreq-H5.patch
[ o.k. ] * [l][c] sun8i-set-machid.patch
[ o.k. ] * [l][c] video-fix-vsync-polarity-bits.patch
[ o.k. ] * [l][b] workaround-reboot-is-poweroff-olimex-a20.patch
HOSTCC scripts/basic/fixdep
HOSTCC scripts/kconfig/conf.o
SHIPPED scripts/kconfig/zconf.tab.c
SHIPPED scripts/kconfig/zconf.lex.c
SHIPPED scripts/kconfig/zconf.hash.c
HOSTCC scripts/kconfig/zconf.tab.o
HOSTLD scripts/kconfig/conf
***
*** Can't find default configuration "arch/../configs/orangepi_plus2_defconfig"!
***
scripts/kconfig/Makefile:121: recipe for target 'orangepi_plus2_defconfig' failed
make[1]: *** [orangepi_plus2_defconfig] Error 1
Makefile:479: recipe for target 'orangepi_plus2_defconfig' failed
make: *** [orangepi_plus2_defconfig] Error 2
sed: can't read .config: No such file or directory
scripts/kconfig/conf --silentoldconfig Kconfig
***
*** Configuration file ".config" not found!
***
*** Please run some configurator (e.g. "make oldconfig" or
*** "make menuconfig" or "make xconfig").
***
scripts/kconfig/Makefile:46: recipe for target 'silentoldconfig' failed
make[2]: *** [silentoldconfig] Error 1
Makefile:479: recipe for target 'silentoldconfig' failed
make[1]: *** [silentoldconfig] Error 2
make: *** No rule to make target 'include/config/auto.conf', needed by 'include/config/uboot.release'. Stop.
[ error ] ERROR in function compile_uboot [ compilation.sh:156 ]
[ error ] U-boot compilation failed
[ o.k. ] Process terminated

We end up with ERROR messages again. Clearly, it’s because U-Boot does NOT support orangepi_plus2_defconfig. Therefore, we do the same to U-Boot board configuration by two steps:

1) STEP 1:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$ cd ./cache/sources/u-boot/v2017.11/configs
$ ls -1 *orangepi*
orangepi_2_defconfig
orangepi_2_defconfig.orig
orangepi_lite_defconfig
orangepi_one_defconfig
orangepi_pc2_defconfig
orangepi_pc2_defconfig.orig
orangepi_pc_defconfig
orangepi_pc_plus_defconfig
orangepi_plus2e_defconfig
orangepi_plus2e_defconfig.orig
orangepi_plus_defconfig
orangepi_plus_defconfig.orig
orangepi_prime_defconfig
orangepi_win_defconfig
orangepi_win_defconfig.orig
orangepi_zero_defconfig
orangepi_zero_defconfig.orig
orangepi_zero_plus2_defconfig
orangepi_zero_plus2_h3_defconfig
orangepizero_plus_defconfig

Clearly, orangepi_plus2_defconfig is NOT in the list. Therefore, we do:

1
2
$ sudo cp orangepi_plus2e_defconfig orangepi_plus2_defconfig
$ sudo vim orangepi_plus2_defconfig

and ensure any plus2e is now plus2.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
$ cat orangepi_plus2_defconfig
CONFIG_ARM=y
CONFIG_ARCH_SUNXI=y
CONFIG_MACH_SUN8I_H3=y
CONFIG_DRAM_CLK=624
CONFIG_DRAM_ZQ=3881979
CONFIG_DRAM_ODT_EN=y
CONFIG_MACPWR="PD6"
CONFIG_MMC_SUNXI_SLOT_EXTRA=2
CONFIG_DEFAULT_DEVICE_TREE="sun8i-h3-orangepi-plus2"
# CONFIG_SYS_MALLOC_CLEAR_ON_INIT is not set
CONFIG_SPL=y
CONFIG_SPL_I2C_SUPPORT=y
# CONFIG_CMD_FLASH is not set
# CONFIG_CMD_FPGA is not set
# CONFIG_SPL_DOS_PARTITION is not set
# CONFIG_SPL_ISO_PARTITION is not set
# CONFIG_SPL_EFI_PARTITION is not set
CONFIG_SUN8I_EMAC=y
CONFIG_SY8106A_POWER=y
CONFIG_USB_EHCI_HCD=y
CONFIG_SYS_USB_EVENT_POLL_VIA_INT_QUEUE=y

2) STEP 2:

1
2
3
4
5
6
7
8
9
10
$ cd ./cache/sources/u-boot/v2017.11/arch/arm/dts
$ ls -1 *sun8i-h3-orangepi*
sun8i-h3-orangepi-2.dts
sun8i-h3-orangepi-lite.dts
sun8i-h3-orangepi-one.dts
sun8i-h3-orangepi-pc.dts
sun8i-h3-orangepi-pc-plus.dts
sun8i-h3-orangepi-plus2e.dts
sun8i-h3-orangepi-plus.dts
sun8i-h3-orangepi-zeroplus2.dts

Clearly, sun8i-h3-orangepi-plus2.dts is NOT in the list. Therefore, we do:

1
2
$ sudo cp sun8i-h3-orangepi-plus2e.dts sun8i-h3-orangepi-plus2.dts
$ sudo vim sun8i-h3-orangepi-plus2.dts

and ensure any 2e/2E is now 2.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
$ cat sun8i-h3-orangepi-plus2.dts
...... // ignore
/*
* The Orange Pi Plus 2 is an extended version of the Orange Pi PC Plus 2,
* with 2G RAM and an external gbit ethernet phy.
*/

#include "sun8i-h3-orangepi-pc-plus.dts"

/ {
model = "Xunlong Orange Pi Plus 2";
compatible = "xunlong,orangepi-plus2", "allwinner,sun8i-h3";

reg_gmac_3v3: gmac-3v3 {
compatible = "regulator-fixed";
pinctrl-names = "default";
pinctrl-0 = <&gmac_power_pin_orangepi>;
regulator-name = "gmac-3v3";
regulator-min-microvolt = <3300000>;
regulator-max-microvolt = <3300000>;
startup-delay-us = <100000>;
enable-active-high;
gpio = <&pio 3 6 GPIO_ACTIVE_HIGH>;
};
};

&emac {
/* The Orange Pi Plus 2 uses an external gbit phy */
pinctrl-names = "default";
pinctrl-0 = <&emac_rgmii_pins>;
phy-supply = <&reg_gmac_3v3>;
phy-mode = "rgmii";
/delete-property/allwinner,use-internal-phy;
};

&pio {
gmac_power_pin_orangepi: gmac_power_pin@0 {
allwinner,pins = "PD6";
allwinner,function = "gpio_out";
allwinner,drive = <SUN4I_PINCTRL_10_MA>;
allwinner,pull = <SUN4I_PINCTRL_NO_PULL>;
};
};

5. Build the Newest Supported Linux Kernels

Before we build the system again, we just need to ensure our python is of version 2 instead of 3, otherwise, you’ll get some ERROR message like:

1
ImportError: No module named _libfdt

NOW, we build the system AGAIN:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
$ ./compile.sh BOARD="orangepiplus2" BRANCH="next" KERNEL_ONLY="yes" KERNEL_CONFIGURE="no"
[ o.k. ] Using config file [ config-default.conf ]
[ warn ] This script requires root privileges, trying to use sudo
[ o.k. ] Using config file [ config-default.conf ]
[ o.k. ] This script will try to update
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Already on 'master'
Your branch is up-to-date with 'origin/master'.
[ o.k. ] Command line: setting BOARD to [ orangepiplus2 ]
[ o.k. ] Command line: setting BRANCH to [ next ]
[ o.k. ] Command line: setting KERNEL_ONLY to [ yes ]
[ o.k. ] Command line: setting KERNEL_CONFIGURE to [ no ]
[ o.k. ] Preparing [ host ]
[ o.k. ] Build host OS release [ xenial ]
[ o.k. ] Syncing clock [ host ]
[ o.k. ] Downloading sources
[ o.k. ] Checking git sources [ u-boot v2017.11 ]
[ .... ] Checking out
[ o.k. ] Checking git sources [ linux-mainline linux-4.14.y ]
[ .... ] Up to date
[ o.k. ] Checking git sources [ sunxi-tools master ]
[ .... ] Up to date
[ o.k. ] Checking git sources [ rkbin-tools master ]
[ .... ] Up to date
[ o.k. ] Checking git sources [ marvell-tools A3700_utils-armada-17.10 ]
[ .... ] Up to date
[ o.k. ] Checking git sources [ odroidc2-blobs master ]
[ .... ] Up to date
[ o.k. ] Cleaning output/debs for [ orangepiplus2 next ]
[ o.k. ] Cleaning [ u-boot/v2017.11 ]
[ o.k. ] Compiling u-boot [ 2017.11 ]
[ o.k. ] Compiler version [ arm-linux-gnueabihf-gcc 7.2.1 ]
[ .... ] Checking out sources
[ o.k. ] Cleaning [ u-boot/v2017.11 ]
[ o.k. ] Started patching process for [ u-boot sunxi-orangepiplus2-next ]
[ o.k. ] Looking for user patches in [ userpatches/u-boot/u-boot-sunxi ]
[ o.k. ] * [l][c] 0020-sunxi-call-fdt_fixup_ethernet-again-to-set-macaddr-f.patch
[ o.k. ] * [l][c] 4kfix-limit-screen-to-full-hd.patch
[ o.k. ] * [l][c] Add-A20-Olimex-SOM204-EVB-board.patch
[ o.k. ] * [l][c] add-a20-olinuxino-micro-emmc-support.patch
[ o.k. ] * [l][c] add-a20-optional-eMMC.patch
[ o.k. ] * [l][c] add-bananapi-bpi-m2-zero.patch
[ o.k. ] * [l][c] add-beelink-x2.patch
[ o.k. ] * [l][c] add-nanopi-air-emmc.patch
[ o.k. ] * [l][c] add-nanopi-duo.patch
[ o.k. ] * [l][c] add-nanopi-m1-plus2-emmc.patch
[ o.k. ] * [l][c] add-nanopineoplus2.patch
[ o.k. ] * [l][c] add-orangepi-plus2-emmc.patch
[ o.k. ] * [l][c] add-orangepi-zeroplus.patch
[ o.k. ] * [l][c] add-orangepi-zeroplus2_h3.patch
[ o.k. ] * [l][c] add-sunvell-r69.patch
[ o.k. ] * [l][c] add-tritium.patch
[ o.k. ] * [l][c] add_emmc_olinuxino_a64.patch
[ o.k. ] * [l][c] add_emmc_orangepiwin.patch
[ o.k. ] * [l][c] adjust-default-dram-clockspeeds.patch
[ o.k. ] * [l][c] adjust-small-boards-cpufreq.patch
[ o.k. ] * [l][c] enable-DT-overlays-support.patch
[ o.k. ] * [l][c] enable-autoboot-keyed.patch
[ o.k. ] * [l][c] fdt-setprop-fix-unaligned-access.patch
[ o.k. ] * [l][c] fix-sdcard-detect-bpi-m2z.patch
[ o.k. ] * [l][c] fix-sunxi-gpio-driver.patch
[ o.k. ] * [l][c] fix-usb1-vbus-opiwin.patch
[ o.k. ] * [l][c] h3-Fix-PLL1-setup-to-never-use-dividers.patch
[ o.k. ] * [l][c] h3-enable-power-led.patch
[ o.k. ] * [l][c] h3-set-safe-axi_apb-clock-dividers.patch
[ o.k. ] * [l][c] lower-default-DRAM-freq-A64-H5.patch
[ o.k. ] * [l][c] lower-default-cpufreq-H5.patch
[ o.k. ] * [l][c] sun8i-set-machid.patch
[ o.k. ] * [l][c] video-fix-vsync-polarity-bits.patch
[ o.k. ] * [l][b] workaround-reboot-is-poweroff-olimex-a20.patch
HOSTCC scripts/basic/fixdep
HOSTCC scripts/kconfig/conf.o
HOSTCC scripts/kconfig/zconf.tab.o
HOSTLD scripts/kconfig/conf
#
# configuration written to .config
#
scripts/kconfig/conf --silentoldconfig Kconfig
.config:1120:warning: override: reassigning to symbol BOOTDELAY
#
# configuration written to .config
#
CHK include/config.h
UPD include/config.h
GEN include/autoconf.mk.dep
CFG u-boot.cfg
CFG spl/u-boot.cfg
GEN include/autoconf.mk
GEN spl/include/autoconf.mk
CHK include/config/uboot.release
CHK include/generated/timestamp_autogenerated.h
UPD include/generated/timestamp_autogenerated.h
UPD include/config/uboot.release
CHK include/generated/version_autogenerated.h
HOSTCC scripts/dtc/dtc.o
......

And, it took me about 5 minutes to have everything built.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
......
patching file tools/include/tools/be_byteshift.h
patching file tools/include/tools/le_byteshift.h
CLEAN scripts/basic
CLEAN scripts/dtc
CLEAN scripts/kconfig
CLEAN scripts/mod
CLEAN scripts/selinux/genheaders
CLEAN scripts/selinux/mdp
CLEAN scripts
dpkg-deb: building package 'linux-dtb-next-sunxi' in '../linux-dtb-next-sunxi_5.41_armhf.deb'.
dpkg-deb: building package 'linux-headers-next-sunxi' in '../linux-headers-next-sunxi_5.41_armhf.deb'.
dpkg-deb: building package 'linux-image-next-sunxi' in '../linux-image-next-sunxi_5.41_armhf.deb'.
dpkg-genchanges: warning: package linux-libc-dev-next-sunxi in control file but not in files list
dpkg-genchanges: binary-only upload (no source code included)
dpkg-deb: building package 'linux-source-4.14.22-next-sunxi' in '/home/jiapei/Downloads/OperatingSystems/linux/distros/armbian/armbian/.tmp/linux-source-next-sunxi_5.41_all.deb'.
[ o.k. ] Kernel build done [ @host ]
[ o.k. ] Target directory [ /home/jiapei/Downloads/OperatingSystems/linux/distros/armbian/armbian/output/debs/ ]
[ o.k. ] File name [ linux-image-next-sunxi_5.41_armhf.deb ]
[ o.k. ] Runtime [ 5 min ]

PART C: Copy Linux Kernel DEBs for Orange Pi Plus 2

1
2
3
4
5
6
7
8
9
$ cd ./output/debs
$ ls -1 *
linux-dtb-next-sunxi_5.41_armhf.deb
linux-headers-next-sunxi_5.41_armhf.deb
linux-image-next-sunxi_5.41_armhf.deb
linux-source-next-sunxi_5.41_all.deb
linux-u-boot-next-orangepiplus2_5.41_armhf.deb

extra:

Five .deb files have been successfully generated, and the folder extra is empty.

2. Copy Built DEBs onto TF Card

Since Armbian Ubuntu Desktop has already been installed on our TF card, after plugging TF card back to my host computer again, it’s automatically mounted as /media/jiapei/ab9545b9-0d2d-4927-83f3-fae97ced83a9. Then, we copy all five .deb files onto TF card by:

1
$ cp *.deb /media/jiapei/ab9545b9-0d2d-4927-83f3-fae97ced83a9/home/orangepiplus2/

PART D: Install the Built DEBs, Remove the Old Kernel(s), and Wifi Configuration

Now we plug the TF card back into the Orange Pi Plus 2 board and boot into Armbian Ubuntu Desktop with kernel 3.4.113.

1. Install NEW Linux Kernels

Single command will do.

1
$ sudo dpkg -i *.deb

Install Built DEBs

It’s OK for us NOT to upgrade u-boot.

2. Remove OLD Linux Kernel(s)

Reboot Orange Pi Plus 2 board, and you’ll see the NEW kernel 4.14.22 is now booted successfully. Now, it’s optional for us to remove old kernel(s) 3.4.113. Two commands will do.

1
dpkg --list | grep linux-image

will help to list all installed Linux Kernel. And then, we remove all unwanted kernels, for instance:

1
dpkg --purge linux-image-sun8i

Remove Old Kernels

3. Wifi Configuration

As known, Orange Pi Plus 2 board comes with Wifi 2.4G support. To enable Wifi for Orange Pi Plus 2 board, we need to make sure there are ONLY 3 effective lines in file /etc/network/interfaces:

1
2
3
source /etc/network/interfaces.d/*
auto lo
iface lo inet loopback

Network Interfaces

Finally, you are recommended to solve all the other issues about Ubuntu Desktop via Google.

Hi, all, I flied back and forth between ShenZhen China and Vancouver Canada in January 2018, and took a holiday break in California USA during Chinese Spring Festival in Febrary 2018. Now, I’m back to Vancouver and write this blog. Today, we are going to talk about how to flash the most recent Linux Kernel onto an NanoPi NEO. The board looks like (cited from NanoPi NEO ):

NanoPi NEO

Different from our previous blog where U-Boot and Linux Kernel are manually built, here, we download and install the built Ubuntu from Armbian directly.

Before starting, the following paragraph is cited to explain the relationships among AllWinner, Sunxi and Linaro.

In march 2014, Allwinner joined Linaro as part of the new linaro digital home group. After this, Allwinner stopped communicating with the sunxi community, as linaro membership apparently satisfies the marketing need to be seen as an open source friendly company. Despite Linaro membership, Allwinner still violates the GPL on many counts. (cited from http://linux-sunxi.org/Allwinner .)

PART A: Install Debian Server Built By Armbian onto NanoPi NEO

1. Download Armbian Debian Server for NanoPi NEO

We FIRST go visiting the website https://www.armbian.com/nanopi-neo/ and click Debian server – mainline kernel icon, a file named Armbian_5.38_Nanopineo_Debian_stretch_next_4.14.14.7z will be automatically downloaded.

Then, we extract this .7z file by

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$ 7za e Armbian_5.38_Nanopineo_Debian_stretch_next_4.14.14.7z

7-Zip (A) [64] 9.20 Copyright (c) 1999-2010 Igor Pavlov 2010-11-18
p7zip Version 9.20 (locale=en_CA.UTF-8,Utf16=on,HugeFiles=on,8 CPUs)

Processing archive: Armbian_5.38_Nanopineo_Debian_stretch_next_4.14.14.7z

Extracting Armbian_5.38_Nanopineo_Debian_stretch_next_4.14.14.img
Extracting armbian.txt
Extracting armbian.txt.asc
Extracting Armbian_5.38_Nanopineo_Debian_stretch_next_4.14.14.img.asc
Extracting sha256sum.sha

Everything is Ok

Files: 5
Size: 1396723567
Compressed: 256174798

2. Install Armbian Debian Server for NanoPi NEO

After the extracted image file is prepared, it’s the time to install the Armbian Debian Server onto our TF card. We FIRST format the TF card:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
$ sudo mkfs.ext4 /dev/mmcblk0 
[sudo] password for jiapei:
mke2fs 1.42.13 (17-May-2015)
Found a dos partition table in /dev/mmcblk0
Proceed anyway? (y,n) y
Discarding device blocks: done
Creating filesystem with 3942144 4k blocks and 987360 inodes
Filesystem UUID: bf3f62c9-283d-48fe-a0f3-56ab357f7b94
Superblock backups stored on blocks:
32768, 98304, 163840, 229376, 294912, 819200, 884736, 1605632, 2654208

Allocating group tables: done
Writing inode tables: done
Creating journal (32768 blocks): done

Afterwards, use dd to install the downloaded Armbian Ubuntu Desktop image.

1
2
3
4
5
$ sudo dd bs=4M if=Armbian_5.38_Nanopineo_Debian_stretch_next_4.14.14.img of=/dev/mmcblk0 conv=fsync
[sudo] password for jiapei:
333+0 records in
333+0 records out
1396703232 bytes (1.4 GB, 1.3 GiB) copied, 157.712 s, 8.9 MB/s

PART B: Boot Into Armbian, Network Configuration and Armbian Upgrading

As known, NanoPi NEO comes with NEITHER a HDMI interface for display, NOR a Wifi interface for wireless network connection. Therefore, we may have to find a wired cable, and connect our NanoPi NEO to a router, which also connects with our host computer. Afterwards, we’ll have to find our NanoPi NEO connection via router settings. Here in my case, I’m using a Cisco DPC3848V DOCSIS 3.0 Gateway, with the gateway IP: 192.168.0.1. By visiting http://192.168.0.1 -> Setup -> LAN Setup -> Connected Devices Summary, you should be able to find out which is the newly connected network device, namely NanoPi NEO.

1. SSH Into NanoPi NEO

Through our host computer, SSH into NanoPi NEO:

1
2
3
4
5
6
$ ssh root@192.168.0.76
The authenticity of host '192.168.0.76 (192.168.0.76)' can't be established.
ECDSA key fingerprint is SHA256:L0qZCYEGGallJo9jSpM63TWAYJ4vU/JzIbMJS80Lx8I.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.0.76' (ECDSA) to the list of known hosts.
root@192.168.0.76's password:

Then you input 1234 as the password, you’ll be asked to change your password right away.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
You are required to change your password immediately (root enforced)
_ _ ____ _ _ _
| \ | | __ _ _ __ ___ | _ \(_) | \ | | ___ ___
| \| |/ _` | '_ \ / _ \| |_) | | | \| |/ _ \/ _ \
| |\ | (_| | | | | (_) | __/| | | |\ | __/ (_) |
|_| \_|\__,_|_| |_|\___/|_| |_| |_| \_|\___|\___/


Welcome to ARMBIAN 5.38 stable Debian GNU/Linux 9 (stretch) 4.14.14-sunxi
System load: 0.07 0.04 0.07 Up time: 15 min
Memory usage: 16 % of 240MB IP: 192.168.0.76
CPU temp: 37°C
Usage of /: 7% of 15G

[ General system configuration (beta): armbian-config ]

New to Armbian? Check the documentation first: https://docs.armbian.com
Changing password for root.
(current) UNIX password:
Enter new UNIX password:
Retype new UNIX password:


Thank you for choosing Armbian! Support: www.armbian.com

And then you will be asked to create a new user account.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
Creating a new user account. Press <Ctrl-C> to abort

Please provide a username (eg. your forename): nanopineo
Trying to add user nanopineo
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = "en_US.UTF-8",
LC_ALL = (unset),
LC_MEASUREMENT = "en_CA.UTF-8",
LC_PAPER = "en_CA.UTF-8",
LC_MONETARY = "en_CA.UTF-8",
LC_NAME = "en_CA.UTF-8",
LC_ADDRESS = "en_CA.UTF-8",
LC_NUMERIC = "en_CA.UTF-8",
LC_MESSAGES = "en_US.UTF-8",
LC_TELEPHONE = "en_CA.UTF-8",
LC_IDENTIFICATION = "en_CA.UTF-8",
LC_TIME = "en_CA.UTF-8",
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
Adding user `nanopineo' ...
Adding new group `nanopineo' (1000) ...
Adding new user `nanopineo' (1000) with group `nanopineo' ...
Creating home directory `/home/nanopineo' ...
Copying files from `/etc/skel' ...
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully
Changing the user information for nanopineo
Enter the new value, or press ENTER for the default
Full Name []:
Room Number []:
Work Phone []:
Home Phone []:
Other []:
Is the information correct? [Y/n] Y

Dear nanopineo, your account nanopineo has been created and is sudo enabled.
Please use this account for your daily work from now on.

root@nanopineo:~#

2. Network Configuration

1) Doublecheck IP address

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
root@nanopineo:~# ifconfig
eth0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500
inet 192.168.0.76 netmask 255.255.255.0 broadcast 192.168.0.255
inet6 fe80::dc0b:3cff:fe76:8606 prefixlen 64 scopeid 0x20<link>
ether de:0b:3c:76:86:06 txqueuelen 1000 (Ethernet)
RX packets 1544 bytes 145676 (142.2 KiB)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 667 bytes 63483 (61.9 KiB)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0
device interrupt 33

lo: flags=73<UP,LOOPBACK,RUNNING> mtu 65536
inet 127.0.0.1 netmask 255.0.0.0
inet6 ::1 prefixlen 128 scopeid 0x10<host>
loop txqueuelen 1000 (Local Loopback)
RX packets 0 bytes 0 (0.0 B)
RX errors 0 dropped 0 overruns 0 frame 0
TX packets 0 bytes 0 (0.0 B)
TX errors 0 dropped 0 overruns 0 carrier 0 collisions 0

2) Modify /etc/network/interfaces

I noticed that when you reboot NanoPi NEO, the IP address changed from time to time. The reason why it is so is because the MAC address of NanoPi NEO change randomly after Armbian reboot. Therefore, it’s recommended to manually set a static MAC address for NanoPi NEO in file /etc/network/interfaces.

1
root@nanopineo:~# vim /etc/network/interfaces

Just make sure to uncomment this line hwaddress ether # if you want to set MAC manually and write in a fixed MAC address. The final /etc/network/interfaces for my NanoPi NEO is as follows:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
root@nanopineo:~# cat /etc/network/interfaces
source /etc/network/interfaces.d/*

# Wired adapter #1
allow-hotplug eth0
no-auto-down eth0
iface eth0 inet dhcp
#address 192.168.0.100
#netmask 255.255.255.0
#gateway 192.168.0.1
#dns-nameservers 8.8.8.8 8.8.4.4
hwaddress ether d2:d0:78:47:06:b3 # if you want to set MAC manually
# pre-up /sbin/ifconfig eth0 mtu 3838 # setting MTU for DHCP, static just: mtu 3838


# Wireless adapter #1
# Armbian ships with network-manager installed by default. To save you time
# and hassles consider using 'sudo nmtui' instead of configuring Wi-Fi settings
# manually. The below lines are only meant as an example how configuration could
# be done in an anachronistic way:
#
#allow-hotplug wlan0
#iface wlan0 inet dhcp
#address 192.168.0.100
#netmask 255.255.255.0
#gateway 192.168.0.1
#dns-nameservers 8.8.8.8 8.8.4.4
# wpa-conf /etc/wpa_supplicant/wpa_supplicant.conf
# Disable power saving on compatible chipsets (prevents SSH/connection dropouts over WiFi)
#wireless-mode Managed
#wireless-power off

# Local loopback
auto lo
iface lo inet loopback

And before reboot Armbian, we also need to set a **FIXED** IP address (Here in my case: 192.168.0.36) for the device with the static MAC address you just specified (Here in my case: **d2:d0:78:47:06:b3**).


## 3. Reboot Armbian

Now, reboot Armbian.

```console
root@nanopineo:~# sudo reboot

After a while, ssh into Armbian with created user nanopineo:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
$ ssh nanopineo@192.168.0.36
The authenticity of host '192.168.0.36 (192.168.0.36)' can't be established.
ECDSA key fingerprint is SHA256:L0qZCYEGGallJo9jSpM63TWAYJ4vU/JzIbMJS80Lx8I.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.0.36' (ECDSA) to the list of known hosts.
nanopineo@192.168.0.36's password:
_ _ ____ _ _ _
| \ | | __ _ _ __ ___ | _ \(_) | \ | | ___ ___
| \| |/ _` | '_ \ / _ \| |_) | | | \| |/ _ \/ _ \
| |\ | (_| | | | | (_) | __/| | | |\ | __/ (_) |
|_| \_|\__,_|_| |_|\___/|_| |_| |_| \_|\___|\___/


Welcome to ARMBIAN 5.38 stable Debian GNU/Linux 9 (stretch) 4.14.14-sunxi
System load: 0.99 0.30 0.10 Up time: 0 min
Memory usage: 16 % of 240MB IP: 192.168.0.36
CPU temp: 43°C
Usage of /: 8% of 15G

[ 0 security updates available, 3 updates total: apt upgrade ]
Last check: 2018-03-01 06:30

[ General system configuration (beta): armbian-config ]


nanopineo@nanopineo:~$

4. Armbian Upgrading

Then we simply upgrade Armbian.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
nanopineo@nanopineo:~$ sudo apt update

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

#1) Respect the privacy of others.
#2) Think before you type.
#3) With great power comes great responsibility.

[sudo] password for nanopineo:
Hit:1 http://security.debian.org stretch/updates InRelease
Hit:4 http://apt.armbian.com stretch InRelease
Ign:2 http://cdn-fastly.deb.debian.org/debian stretch InRelease
Hit:3 http://cdn-fastly.deb.debian.org/debian stretch-updates InRelease
Hit:5 http://cdn-fastly.deb.debian.org/debian stretch-backports InRelease
Hit:6 http://cdn-fastly.deb.debian.org/debian stretch Release
Reading package lists... Done
Building dependency tree
Reading state information... Done
3 packages can be upgraded. Run 'apt list --upgradable' to see them.
nanopineo@nanopineo:~$ apt list --upgradable
Listing... Done
linux-dtb-next-sunxi/stretch 5.41 armhf [upgradable from: 5.38]
linux-image-next-sunxi/stretch 5.41 armhf [upgradable from: 5.38]
tzdata/stable-updates 2018c-0+deb9u1 all [upgradable from: 2017c-0+deb9u1]
nanopineo@nanopineo:~$ sudo apt upgrade
Reading package lists... Done
Building dependency tree
Reading state information... Done
Calculating upgrade... Done
The following packages will be upgraded:
linux-dtb-next-sunxi linux-image-next-sunxi tzdata
3 upgraded, 0 newly installed, 0 to remove and 0 not upgraded.
Need to get 20.2 MB of archives.
After this operation, 240 kB of additional disk space will be used.
Do you want to continue? [Y/n] Y
Get:1 http://cdn-fastly.deb.debian.org/debian stretch-updates/main armhf tzdata all 2018c-0+deb9u1 [264 kB]
Get:2 http://apt.armbian.com stretch/main armhf linux-dtb-next-sunxi armhf 5.41 [175 kB]
Get:3 http://apt.armbian.com stretch/main armhf linux-image-next-sunxi armhf 5.41 [19.7 MB]
Fetched 20.2 MB in 14s (1387 kB/s)
perl: warning: Setting locale failed.
perl: warning: Please check that your locale settings:
LANGUAGE = "en_US.UTF-8",
LC_ALL = (unset),
LC_TIME = "en_CA.UTF-8",
LC_MONETARY = "en_CA.UTF-8",
LC_ADDRESS = "en_CA.UTF-8",
LC_TELEPHONE = "en_CA.UTF-8",
LC_MESSAGES = "en_US.UTF-8",
LC_NAME = "en_CA.UTF-8",
LC_MEASUREMENT = "en_CA.UTF-8",
LC_IDENTIFICATION = "en_CA.UTF-8",
LC_NUMERIC = "en_CA.UTF-8",
LC_PAPER = "en_CA.UTF-8",
LANG = "en_US.UTF-8"
are supported and installed on your system.
perl: warning: Falling back to a fallback locale ("en_US.UTF-8").
locale: Cannot set LC_ALL to default locale: No such file or directory
Preconfiguring packages ...
(Reading database ... 32833 files and directories currently installed.)
Preparing to unpack .../tzdata_2018c-0+deb9u1_all.deb ...
Unpacking tzdata (2018c-0+deb9u1) over (2017c-0+deb9u1) ...
Preparing to unpack .../linux-dtb-next-sunxi_5.41_armhf.deb ...
Unpacking linux-dtb-next-sunxi (5.41) over (5.38) ...
Preparing to unpack .../linux-image-next-sunxi_5.41_armhf.deb ...
update-initramfs: Deleting /boot/initrd.img-4.14.14-sunxi
Removing obsolete file uInitrd-4.14.14-sunxi
Unpacking linux-image-next-sunxi (5.41) over (5.38) ...
Setting up linux-dtb-next-sunxi (5.41) ...
Setting up tzdata (2018c-0+deb9u1) ...
locale: Cannot set LC_ALL to default locale: No such file or directory

Current default time zone: 'Etc/UTC'
Local time is now: Thu Mar 1 06:34:05 UTC 2018.
Universal Time is now: Thu Mar 1 06:34:05 UTC 2018.
Run 'dpkg-reconfigure tzdata' if you wish to change it.

Setting up linux-image-next-sunxi (5.41) ...
update-initramfs: Generating /boot/initrd.img-4.14.18-sunxi
update-initramfs: Converting to u-boot format
nanopineo@nanopineo:~$

5. Kernel Doublechecking

Finally, we have the system and kernel doublechecked.

1
2
3
4
5
6
7
8
9
10
11
nanopineo@nanopineo:~$ uname -r
4.14.14-sunxi
nanopineo@nanopineo:~$ uname -a
Linux nanopineo 4.14.14-sunxi #1 SMP Thu Jan 25 12:20:57 CET 2018 armv7l GNU/Linux
nanopineo@nanopineo:~$ lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description: Debian GNU/Linux 9.3 (stretch)
Release: 9.3
Codename: stretch
nanopineo@nanopineo:~$

Happy new year everybody. How time flies. It is already 2018. Longer Vision has been struggling on this tough road towards a successful enterprise. Algorithms ONLY are NOT enough for nowadays business. BSP (board support package) and IC design are a must for a successful business nowadays. Thus, ever since 2018, Longer Vision is going to balance both hardware and software, particularly, ARM based open source embedded development board and computer vision algorithms.

In this blog, we are going to talk about how to build and flash U-Boot and Linux Kernel onto a Beaglebone and Beaglebone Black, which adopts TI AM335x as its CPU. The board looks like (cited from Beaglebone Black ):

Beaglebone Black

PART A: Cross Compile U-Boot and Linux Kernel

1. Linaro GCC

Linaro is a popular platform providing high-quality code for both Linux kernel and GCC tool chain. Linaro’s GCC toolchain of varoius versions can be directly found here.

Here, we download GCC latest-6 binary under arm-linux-gnueabihf.

1
2
3
4
$ wget -c 
https://releases.linaro.org/components/toolchain/binaries/latest-6/arm-linux-gnueabihf/gcc-linaro-6.4.1-2017.11-x86_64_arm-linux-gnueabihf.tar.xz
$ tar xf gcc-linaro-6.4.1-2017.11-x86_64_arm-linux-gnueabihf.tar.xz
$ export CC=`pwd`/gcc-linaro-6.4.1-2017.11-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-

Test the cross compiler:

1
2
3
4
5
$ ${CC}gcc --version
arm-linux-gnueabihf-gcc (Linaro GCC 6.4-2017.11) 6.4.1 20171012
Copyright (C) 2017 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.

2. U-Boot

U-Boot is a universal boot loader. For Beaglebone and Beaglebone Black, there are two patches which has been maintained by eewiki Linux on ARM on github. We first download U-Boot and check out the latest release as follows:

1
2
3
$ git clone https://github.com/u-boot/u-boot
$ cd u-boot/
$ git checkout v2018.01

Then check out the latest u-boot-patches and patch two files under the latest release v2018.01:

1
2
3
4
5
6
7
8
$ cd ../
$ git clone https://github.com/eewiki/u-boot-patches.git
$ cd ./u-boot-patches/v2018.01
$ cp 0001-am335x_evm-uEnv.txt-bootz-n-fixes.patch ../../u-boot/
$ cp 0002-U-Boot-BeagleBone-Cape-Manager.patch ../../u-boot/
$ cd ../../u-boot
$ patch -p1 < 0001-am335x_evm-uEnv.txt-bootz-n-fixes.patch
$ patch -p1 < 0002-U-Boot-BeagleBone-Cape-Manager.patch

Finally, we configure and build U-Boot for Beaglebone and Beaglebone Black as follows:

1
2
3
$ make ARCH=arm CROSS_COMPILE=${CC} distclean
$ make ARCH=arm CROSS_COMPILE=${CC} am335x_evm_defconfig
$ make ARCH=arm CROSS_COMPILE=${CC}

3. Linux Kernel

Due to Robert Nelson’s summary at eewiki, there are two ways to build Beaglebone and Beaglebone Black: - Mainline - TI BSP

Their differences are: - bb-kernel: based on mainline, no-smp, optimized for AM335x devices. - ti-linux-kernel-dev: based on TI’s git tree, smp, optimized for AM335x/AM43xx/AM57x devices.

Here, we are going to use Mainline to build our own Linux Kernel. We FIRST check out Robert Nelson’s bb-kernel.

1
2
3
$ git clone https://github.com/RobertCNelson/bb-kernel
$ cd bb-kernel/
$ git checkout origin/am33x-v4.14 -b am33x-v4.14

We then check out Linus Torvalds’ stable Linux Kernel, which can be also tracked on github Torvalds Linux. This will take you quite a while.

1
$ git clone https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux-stable.git

Now, it’s the time to modify some of the configurations in .sh files under the checked out branch am33x-v4.14.

1) version.sh

Here, I’m using gcc_linaro_gnueabihf_6 instead of gcc_linaro_gnueabihf_7.

1
2
toolchain="gcc_linaro_gnueabihf_6"
#toolchain="gcc_linaro_gnueabihf_7"

2) system.sh

A file named system.sh.sample has been provided for us to configure accordingly. We FIRST do a copy.

1
$ cp system.sh.sample system.sh

Then, we manually re-specifying two MACROs: CC and LINUX_GIT, respectively to two directories containing the above downloaded Linaro GCC compiler and the current Torvalds’ Linux Kernel. We also specify MMC for TF/SD Card as follows:

1
2
3
CC=.../gcc-linaro-6.4.1-2017.11-x86_64_arm-linux-gnueabihf/bin/arm-linux-gnueabihf-
LINUX_GIT=.../linux-stable
MMC=/dev/mmcblk0

After the above configurations, we start building the Linux Kernel using the following command line. This will probably take you one hour.

1
$ ./build_kernel.sh

When you see this Kernel Configuration page,

Kernel Configuration

Exit right away without any modification. And you will see:

After Kernel Configuration

After a while, you will see Linux Kernel has been successfully built:

The Built Kernel

4. Root File System

We then install the latest Debian (for now, Debian 9.3) according to Robert Nelson’s minimal operating system. Three commands are to be executed in a row for downloading, verifying, and extraction.

1
2
3
4
$ wget -c https://rcn-ee.com/rootfs/eewiki/minfs/debian-9.3-minimal-armhf-2017-12-09.tar.xz
$ sha256sum debian-9.3-minimal-armhf-2017-12-09.tar.xz
5120fcfb8ff8af013737fae52dc0a7ecc2f52563a9aa8f5aa288aff0f3943d61 debian-9.3-minimal-armhf-2017-12-09.tar.xz
$ tar xf debian-9.3-minimal-armhf-2017-12-09.tar.xz

Until now, most components for booting have been downloaded and built. It is the time for us to flash our own OS onto a SD card.

PART B: Install the Linux OS onto SD Card

5. Setup microSD card

1) TF Card Preparation

We first check which block device that we are going to install our built system onto by command lsblk.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
$ lsblk
NAME MAJ:MIN RM SIZE RO TYPE MOUNTPOINT
sdd 8:48 0 931.5G 0 disk
└─sdd1 8:49 0 931.5G 0 part /media/jiapei/Data
sdb 8:16 0 238.5G 0 disk
├─sdb4 8:20 0 900M 0 part
├─sdb2 8:18 0 128M 0 part
├─sdb3 8:19 0 237.2G 0 part /media/jiapei/Win10
└─sdb1 8:17 0 300M 0 part /boot/efi
sr0 11:0 1 1024M 0 rom
sdc 8:32 0 238.5G 0 disk
├─sdc2 8:34 0 30.5G 0 part [SWAP]
├─sdc3 8:35 0 207.5G 0 part /
└─sdc1 8:33 0 512M 0 part
mmcblk0 179:0 0 15G 0 disk

We then define a MACRO DISK to specify the TF card device.

1
$ export DISK=/dev/mmcblk0

Afterwards, erase partition table/labels on TF card by:

1
$ sudo dd if=/dev/zero of=${DISK} bs=1M count=10

2) Bootloader installation

Now, we install the built U-Boot onto the SD card:

1
2
$ sudo dd if=./u-boot/MLO of=${DISK} count=1 seek=1 bs=128k
$ sudo dd if=./u-boot/u-boot.img of=${DISK} count=2 seek=1 bs=384k

3) Partition Preparation

We FIRST make sure which version of sfdisk is. In my case, it is of version 2.27.1

1
2
$ sudo sfdisk --version
sfdisk from util-linux 2.27.1

Then we create the partition layout by:

1
2
3
$ sudo sfdisk ${DISK} <<-__EOF__
4M,,L,*
__EOF__

Afterwards, we need to format the created partition by mkfs.ext4. We also need to make sure which version of mkfs.ext4 is. In my case, it is of version 1.42.13.

1
2
3
$ mkfs.ext4 -V
mke2fs 1.42.13 (17-May-2015)
Using EXT2FS Library version 1.42.13

Then, we format the partition by:

1
$ sudo mkfs.ext4 -L rootfs ${DISK}p1

After formatting, the TF card should be able to be either automatically mounted or manually mounted by the following command:

1
2
$ sudo mkdir -p /media/rootfs/
$ sudo mount ${DISK}p1 /media/rootfs/

4) Backup Bootloader

1
2
3
$ sudo mkdir -p /media/rootfs/opt/backup/uboot/
$ sudo cp -v ./u-boot/MLO /media/rootfs/opt/backup/uboot/
$ sudo cp -v ./u-boot/u-boot.img /media/rootfs/opt/backup/uboot/

5) Dealing with old Bootloader in eMMC (Optional)

If the old bootloader in eMMC is to be kept, please copy the following file uEnv.txt to /media/rootfs/.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
##This will work with: Angstrom's 2013.06.20 u-boot.

loadaddr=0x82000000
fdtaddr=0x88000000
rdaddr=0x88080000

initrd_high=0xffffffff
fdt_high=0xffffffff

#for single partitions:
mmcroot=/dev/mmcblk0p1

loadximage=load mmc 0:1 ${loadaddr} /boot/vmlinuz-${uname_r}
loadxfdt=load mmc 0:1 ${fdtaddr} /boot/dtbs/${uname_r}/${fdtfile}
loadxrd=load mmc 0:1 ${rdaddr} /boot/initrd.img-${uname_r}; setenv rdsize ${filesize}
loaduEnvtxt=load mmc 0:1 ${loadaddr} /boot/uEnv.txt ; env import -t ${loadaddr} ${filesize};
loadall=run loaduEnvtxt; run loadximage; run loadxfdt;

mmcargs=setenv bootargs console=tty0 console=${console} ${optargs} ${cape_disable} ${cape_enable} root=${mmcroot} rootfstype=${mmcrootfstype} ${cmdline}

uenvcmd=run loadall; run mmcargs; bootz ${loadaddr} - ${fdtaddr};
1
sudo cp -v ./uEnv.txt /media/rootfs/

6. Kernel Installation

1) Export MACRO kernel_version

Under the folder bb-kernel, a file named kernel_version was generated while building Linux kernel. In my case, I was building the NEWEST kernel 4.14.13-bone12. For convenience, we export a new MACRO kernel_version.

1
2
3
$ cat kernel_version 
4.14.13-bone12
$ export kernel_version=4.14.13-bone12

2) Extract Debian Root File System onto TF Card

1
2
3
4
$ sudo tar xfvp ./debian-9.3-minimal-armhf-2017-12-09/armhf-rootfs-debian-stretch.tar -C /media/rootfs/
$ sync
$ sudo chown root:root /media/rootfs/
$ sudo chmod 755 /media/rootfs/

3) Set uname_r in /boot/uEnv.txt

1
$ sudo sh -c "echo 'uname_r=${kernel_version}' >> /media/rootfs/boot/uEnv.txt"

4) Copy Kernel Image

1
$ sudo cp -v ./bb-kernel/deploy/${kernel_version}.zImage /media/rootfs/boot/vmlinuz-${kernel_version}

5) Copy Kernel Device Tree Binaries

1
2
$ sudo mkdir -p /media/rootfs/boot/dtbs/${kernel_version}/
$ sudo tar xfv ./bb-kernel/deploy/${kernel_version}-dtbs.tar.gz -C /media/rootfs/boot/dtbs/${kernel_version}/

6) Copy Kernel Modules

1
$ sudo tar xfv ./bb-kernel/deploy/${kernel_version}-modules.tar.gz -C /media/rootfs/

7) Set File Systems Table (/etc/fstab)

1
$ sudo sh -c "echo '/dev/mmcblk0p1  /  auto  errors=remount-ro  0  1' >> /media/rootfs/etc/fstab"

8) Networking

To enable the Internet for the FIRST booting, we need to do the network configuration:

1
$ sudo nano /media/rootfs/etc/network/interfaces

Add the following content:

1
2
3
4
5
auto lo
iface lo inet loopback

auto eth0
iface eth0 inet dhcp

In order to use a shared SD card with multiple BeagleBones, and always enable the Ethernet interface as eth0, we need to add a particular udev rule as:

1
$ sudo nano /media/rootfs/etc/udev/rules.d/70-persistent-net.rules

Add the following content:

1
2
# BeagleBone: net device ()
SUBSYSTEM=="net", ACTION=="add", DRIVERS=="?*", ATTR{dev_id}=="0x0", ATTR{type}=="1", KERNEL=="eth*", NAME="eth0"

9) Remove TF Card

1
2
$ sync
$ sudo umount /media/rootfs

PART C: Configurations after Booting from the SD Card

Insert TF card into a Beaglebone Black, connect BBB with an Internet cable, and connect a Micro HDMI cable on demand. After the flashing of on-board LEDs, you should be able to find the IP address of BBB via your router. All our future jobs are to be done via ssh command through this IP address. My personal preference is to set a static IP address for this particularly BBB in the router settings.

Preparation

By reading two of our previous blogs Camera Calibration Using a Chessboard and Camera Posture Estimation Using Circle Grid Pattern, it wouldn’t be hard to replace the chessboard by a circle grid to calculate camera calibration parameters.

Coding

Our code can be found at OpenCV Examples.

First of all

As mentioned in Camera Calibration Using a Chessboard, for intrinsic parameters estimation, namely, camera calibration, there is NO need to measure the circle unit size. And the circle gird is to be adopted is exactly the same one as used in Camera Posture Estimation Using Circle Grid Pattern:

asymmetric_circle_grid

Secondly

Required packages need to be imported.

1
2
3
import numpy as np
import cv2
import yam

Thirdly

Some initialization work need to be done, including: 1) define the termination criteria when refine the corner sub-pixel later on; 2) blob detection parameters; 3) object points coordinators initialization.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# termination criteria
criteria = (cv2.TERM_CRITERIA_EPS + cv2.TERM_CRITERIA_MAX_ITER, 30, 0.001)

########################################Blob Detector##############################################

# Setup SimpleBlobDetector parameters.
blobParams = cv2.SimpleBlobDetector_Params()

# Change thresholds
blobParams.minThreshold = 8
blobParams.maxThreshold = 255

# Filter by Area.
blobParams.filterByArea = True
blobParams.minArea = 64 # minArea may be adjusted to suit for your experiment
blobParams.maxArea = 2500 # maxArea may be adjusted to suit for your experiment

# Filter by Circularity
blobParams.filterByCircularity = True
blobParams.minCircularity = 0.1

# Filter by Convexity
blobParams.filterByConvexity = True
blobParams.minConvexity = 0.87

# Filter by Inertia
blobParams.filterByInertia = True
blobParams.minInertiaRatio = 0.01

# Create a detector with the parameters
blobDetector = cv2.SimpleBlobDetector_create(blobParams)

###################################################################################################

###################################################################################################

# Original blob coordinates, supposing all blobs are of z-coordinates 0
# And, the distance between every two neighbour blob circle centers is 72 centimetres
# In fact, any number can be used to replace 72.
# Namely, the real size of the circle is pointless while calculating camera calibration parameters.
objp = np.zeros((44, 3), np.float32)
objp[0] = (0 , 0 , 0)
objp[1] = (0 , 72 , 0)
objp[2] = (0 , 144, 0)
objp[3] = (0 , 216, 0)
objp[4] = (36 , 36 , 0)
objp[5] = (36 , 108, 0)
objp[6] = (36 , 180, 0)
objp[7] = (36 , 252, 0)
objp[8] = (72 , 0 , 0)
objp[9] = (72 , 72 , 0)
objp[10] = (72 , 144, 0)
objp[11] = (72 , 216, 0)
objp[12] = (108, 36, 0)
objp[13] = (108, 108, 0)
objp[14] = (108, 180, 0)
objp[15] = (108, 252, 0)
objp[16] = (144, 0 , 0)
objp[17] = (144, 72 , 0)
objp[18] = (144, 144, 0)
objp[19] = (144, 216, 0)
objp[20] = (180, 36 , 0)
objp[21] = (180, 108, 0)
objp[22] = (180, 180, 0)
objp[23] = (180, 252, 0)
objp[24] = (216, 0 , 0)
objp[25] = (216, 72 , 0)
objp[26] = (216, 144, 0)
objp[27] = (216, 216, 0)
objp[28] = (252, 36 , 0)
objp[29] = (252, 108, 0)
objp[30] = (252, 180, 0)
objp[31] = (252, 252, 0)
objp[32] = (288, 0 , 0)
objp[33] = (288, 72 , 0)
objp[34] = (288, 144, 0)
objp[35] = (288, 216, 0)
objp[36] = (324, 36 , 0)
objp[37] = (324, 108, 0)
objp[38] = (324, 180, 0)
objp[39] = (324, 252, 0)
objp[40] = (360, 0 , 0)
objp[41] = (360, 72 , 0)
objp[42] = (360, 144, 0)
objp[43] = (360, 216, 0)
###################################################################################################

# Arrays to store object points and image points from all the images.
objpoints = [] # 3d point in real world space
imgpoints = [] # 2d points in image plane.

Fourthly

After localizing 10 frames (10 can be changed to any positive integer as you wish) of a grid of 2D circles, camera matrix and distortion coefficients can be calculated by invoking the function calibrateCamera. Here, we are testing on a real-time camera stream. Similar to Camera Posture Estimation Using Circle Grid Pattern, the trick is to do blobDetector.detect() and draw the detected blobs using cv2.drawKeypoints() before invoking cv2.findCirclesGrid(), so that the entire grid is easier to be found.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
cap = cv2.VideoCapture(0)
found = 0
while(found < 10): # Here, 10 can be changed to whatever number you like to choose
ret, img = cap.read() # Capture frame-by-frame
gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)

keypoints = blobDetector.detect(gray) # Detect blobs.

# Draw detected blobs as red circles. This helps cv2.findCirclesGrid() .
im_with_keypoints = cv2.drawKeypoints(img, keypoints, np.array([]), (0,255,0), cv2.DRAW_MATCHES_FLAGS_DRAW_RICH_KEYPOINTS)
im_with_keypoints_gray = cv2.cvtColor(im_with_keypoints, cv2.COLOR_BGR2GRAY)
ret, corners = cv2.findCirclesGrid(im_with_keypoints, (4,11), None, flags = cv2.CALIB_CB_ASYMMETRIC_GRID) # Find the circle grid

if ret == True:
objpoints.append(objp) # Certainly, every loop objp is the same, in 3D.

corners2 = cv2.cornerSubPix(im_with_keypoints_gray, corners, (11,11), (-1,-1), criteria) # Refines the corner locations.
imgpoints.append(corners2)

# Draw and display the corners.
im_with_keypoints = cv2.drawChessboardCorners(img, (4,11), corners2, ret)
found += 1

cv2.imshow("img", im_with_keypoints) # display
cv2.waitKey(2)

# When everything done, release the capture
cap.release()
cv2.destroyAllWindows()

ret, mtx, dist, rvecs, tvecs = cv2.calibrateCamera(objpoints, imgpoints, gray.shape[::-1], None, None)

Finally

Write the calculated calibration parameters into a yaml file. Here, it is a bit tricky. Please bear in mind that you MUST call function tolist() to transform a numpy array to a list.

1
2
3
4
# It's very important to transform the matrix to list.
data = {'camera_matrix': np.asarray(mtx).tolist(), 'dist_coeff': np.asarray(dist).tolist()}
with open("calibration.yaml", "w") as f:
yaml.dump(data, f)

Additionally

You may use the following piece of code to load the calibration parameters from file “calibration.yaml”.

1
2
3
4
with open('calibration.yaml') as f:
loadeddict = yaml.load(f)
mtxloaded = loadeddict.get('camera_matrix')
distloaded = loadeddict.get('dist_coeff')
0%