2021年7月24日 星期六

c++ const method

 一個method被標記為const 表示他不會改變所屬class的member,function若能被標記為const應盡量這麼做

class A{
  int b;
  void c(){
      b = 0; // compiling error
  };
};

c++ const method

pixel 3a navigation button die

 I found sometimes my pixel 3a's navigation buttons die, sometimes include lower part of the keyboard, which is really annoying, make me can't go back to last page / home or typing.

Recently I found out it's cause by high temperature (but not extremely high, hence I'm still holding it by my hand), putting a usb fan behind it could release the situation.

pixel 3a 的鍵盤下半部(導航鍵與鍵盤下半部,包含倒退鍵) 有時候會失去作用或變得很遲鈍,最近發現是溫度造成的,將風扇在手機背面,一切就會復原了。但其實也不是多高溫,因為還能用手拿著..

pixel 3a navigation button die

2021年7月23日 星期五

Lowe's Ratio Test排除易混淆特徵點對應

 再做特徵點對應的時候,若有重複的圖形,用local資訊提取的特徵很容易有錯誤的對應

所以可以用 Lowe's Ratio Test 排除易混淆的對應,意義上來說是如果有相近的對應就將該組對應排除

這個方法很簡單, Lowe在SIFT原始論文就有提出這個方法, 在7.1

https://www.cs.ubc.ca/~lowe/papers/ijcv04.pdf

L1,L2 是最相近的對應特徵點與二相近的對應特徵點對應分數

L2/L1 = RoD (ration of distance)

原始論文中建議設為0.8, 但可能做3D重建更介意false positive,設為0.5

Lowe's Ratio Test排除易混淆特徵點對應

Bag of visual words,TF-IDF

Bag of visual words (BOVW)是把影像用特徵來描述

譬如說用SIFT提取特徵,之後一張影像就用這些特徵來表示,並且也只保留這些特徵,

這可以用在影像特徵的萃取與比對

一張影像可以提取出許多字彙,直接用每個字彙出現的數量來描述影像是一種方式

而應用TF-IDF (Term freq. inverse document frequency )的技術,在此描述中加上字彙的稀有程度這項因素

t = (nid/nd) log(N/ni) 

nid:字彙i出現在目標影像中的次數

nd :目標影像總字數

N:總影像數

ni:含有字彙i的影像數

(nid/nd)這項表示若這張影像的字彙數越少,每個字彙的權重越高

(log(N/ni))這項表示若這字彙越稀有,則這個字彙權重越高

接著再計算影像之間的cosine distance, 

ref :  https://www.youtube.com/watch?v=a4cFONdc6nc

ref :https://github.com/ovysotska/in_simple_english

Bag of visual words,TF-IDF

2021年7月22日 星期四

Ubuntu suspend problem

 When using Ubuntu 18.04, there's always buggy blank screen / suspend action that force me to reboot my PC

The easiest one is blank the screen, than unplug your second screen, boom your PC die..

so I just change to xscreensaver

$ sudo apt-get install xscreensaver xscreensaver-gl-extra xscreensaver-data-extra

then remove buggy gnome -screensaver

$ sudo apt-get remove gnome-screensaver

then search for startup and add an entry

Ubuntu suspend problem

Git traped?

 I've a file in a Git control project that I've do some local change, and don't want it to be overwrite.

so I use

$ git update-index --skip-worktree <file-list>

to avoid the over write

but strange thing happen today when I'm trying to checkout another branch, Git ask me to commit / stash local change, but when I stash local change

git> No local change to save

but when I checkout

git > please commit your changes or stash them before you switch branches

my Git version is 2.30.2

so I can only 

$ git update-index --no-skip-worktree <file-list>

then 

$ git stash

$ git checkout

Git traped?

2021年5月28日 星期五

power point 調整圖片透明

Power point沒辦法直接調整圖片透明度,but有個work around
1.插入圖形方塊
*不是直接插入圖片喔
2.將方塊的線條調整成無線條
3.將方塊的背景填滿改成以圖形填滿,再去選擇要插入的圖片,這時候就可以調整透明度囉

測試office版本2019

power point 調整圖片透明

2021年5月27日 星期四

MPV ubuntu 下好用的播放器 video player


本來是用VLC player,但因為有些影片只有部份是有效資訊,vlc的放大跟平移又是世界難用,所以找到了MPV
mpv 基本用法是
$ mpv 要播放的檔名

舊版本自訂熱鍵

用Ubuntu 18.04內建的reopsitry抓到的是有點舊的版本 雖然是可以透過自訂熱鍵達成zoom跟pan,
方法是:
在 ~/.config/mpv/ 中新增 input.conf 內容是
Alt+- add video-zoom -0.25
Alt+= add video-zoom 0.25
Alt+h add video-pan-x 0.05
Alt+l add video-pan-x -0.05
Alt+k add video-pan-y 0.05
Alt+j add video-pan-y -0.05

自行compile

但要是抓新版的就不用這麻煩了
本來想說要去github抓下來自己build,但過程中一直缺fribidi這個套件,
但其中遇到一些問題 
0. 可以先做這步,git 的readme有提到,但我之前沒看到
$ apt-get install devscripts equivs
$ mk-build-deps -s sudo -i
$ dpkg-buildpackage -uc -us -b -j4
完成之後mpv_<version>_<architecture>.deb會在上層目錄被產生,用下面指令安裝
$ sudo dpkg -i ../mpv_<version>_<architecture>.deb
1.需要 fribidi
其實是需要 fribidi-dev 
2.yasm太舊
$ sudo apt-get install yasm 

直接用第三方repository安裝

$ sudo add-apt-repository ppa:mc3man/mpv-tests
$ sudo apt-get install mpv

Hotkeys

alt+方向鍵: pan
alt++/-: zoom

MPV ubuntu 下好用的播放器 video player

2021年5月20日 星期四

[Ubuntu] Silver Searcher , a fast code searching tool

The Silver Searcher 

A code searching tool similar to ack, with a focus on speed.

github

install on ubuntu

sudo apt-get install silversearcher-ag

usage

search i_am_sample_code in /

sudo ag --silent i_am_sample_code /

[Ubuntu] Silver Searcher , a fast code searching tool

2021年5月19日 星期三

Install Bash 5.1 on ubuntu 18.04

在看bash reference manual的時候發現一些功能不能用,懷疑是18.04的bash版本太舊想說更新看看
需要自己build bash
sudo apt-get install build-essential

clone the source 

https://github.com/bminor/bash

cd to the code directory
./configure
make
sudo make install
sh

完成之後,bash會被放到/usr/local/bin/bash
接著如果要指定成預設的shell,要編輯 /etc/shells 將 /usr/local/bin/bash加入
之後再
$ chsh
輸入密碼之後
/usr/local/bin/bash
之後重新登入

Install Bash 5.1 on ubuntu 18.04

cherrytree on ubuntu 18.04

it's hard to install the latest (0.99.36) cherrytree on ubuntu 18.04
I think the easiest way is install the flatpak package
0.99.36 have improved a lot from the default 0.39.4 version, it's worth for update

cherrytree on ubuntu 18.04

2021年5月8日 星期六

[linux] 用sed將文件中的換行換成空白

最近因為需要翻譯(用google translate)一些文件,但那些文件因為排版需要,有很多不必要的換行,擔心會影響到翻譯品質
但有個好處是,他真的要換行的地方連續換行兩次

如果在windows中有msWord,可以用搜尋找出連續換行,取代成特殊符號,再取代獨立的換行
linux中邏輯也類似,但用sed這套很強的搜尋取代程式來做到

除此之外順便把他弄成script,以後要使用比較方便 

$1是來源檔案$2是目標檔案
#!/bin/bash
# remove $1's single \n and save to $2
sed ':a;N;$!ba;s/\n\{2\}/%@%/g;s/\n/ /g; s/%@%/\n/g' $1 > $2

將上面這段存成 fixNl.sh再用
$fixNl.sh source dest

就會將source中了內容轉換dest了

source sample:
1
2
3

4
5
6

7
8
9

dest sample:
1 2 3
4 5 6
7 8 9

[linux] 用sed將文件中的換行換成空白

2021年5月6日 星期四

[C++] && rvalue 暫時存在的Object

 ref

myClass f() {...};
myClass X,Y; 
myClass A(X);        // 1.
myClass B(X+Y);      // 2.
myClass C(f());      // 3.
在三種狀況中 2,3 與 1是不一樣的﹔
 2,3 中的 X+Y與f(X) 都會產生一個暫時性的Object,在執行完該行後消失。
 因此C++ 11為這種狀況搞了個rvalue, 2,3就屬於rvalue
相對於rvalue的就是lvalue
lvalue: locator value: an object that occupies some identifable location in memory: 在記憶體上佔有一定空間的物件 

在 C++ 中有兩種constructor

//copy constructor
myClass(myClass const& other){} 
//move constructor
myClass(myClass&& other){}
其中move constructor就是當傳入的是rvalue (myClass&&)的時候可以做一些特殊處理
譬如說,可以把rvalue的記憶體拿來使用,因為這行程式結束之後rvalue也不不存在了

[C++] && rvalue 暫時存在的Object

[c++] method()=delete

C++11的新功能
這是 suppressing operation
當寫 method()=delete的時候,呼叫method()是被compiler禁止的

[c++] method()=delete

2021年5月5日 星期三

[ubuntu] 文件瀏覽器less使用教學

less使用說明

f下一頁b 上一頁
用/可以向下搜尋字串 n是下一個match shift+n上一個match
g去檔頭G去檔尾,g後面也可以輸入行數
q離開
h叫出使用說明
有趣的是,less的說明也是用less開的

[ubuntu] 文件瀏覽器less使用教學

ubuntu bash教學

$man bash
會用less打開bash的說明書

less 的用法可以參考 less教學

可以搜尋moving
或history等等關鍵字

ubuntu bash教學

[ubuntu] bash 搜尋歷史指令

用
$history 
可以看完整歷史
另外用
ctrl+r可以 往回搜尋之前用過的指令

[ubuntu] bash 搜尋歷史指令

[ubuntu] bash幫指令取縮寫

前面提到要把檔案丟到回收桶要用指令
$gio trash 檔名,可不可以改成用trash?
在~/.bashrc中加入
alias trash='gio trash'
之後再
$source .bashrc就可以囉
其他覺得新手可以加入的alias還有
alias rm='rm -i'
避免一次砍掉太多不該砍的東西
這樣一次真要刪除很多檔案的時候可以用
$rm -I 

[ubuntu] bash幫指令取縮寫

ubuntu刪除多個檔案

上一篇有提到一次建立test1, test2, test3三個檔案的方式,如果要一次刪除他們
$rm test*
這樣就會全部刪掉,但如果怕誤刪其他test什麼的可以用
$rm test* -i
在刪除每個檔案前會再次確認
或是丟到資源回收筒再一次刪除可能比較安心可以用
$gio trash test*

ubuntu刪除多個檔案

ubuntu建立多個檔案