2016年1月20日 星期三

[OpenCV C++] GrabCut 介紹

        OpenCV 中的GrabCut算法是依據《"GrabCut" - Interactive Foreground Extraction using Iterated Graph Cuts》這篇文章來實現的。該算法利用了圖像中的顏色和邊界,只要少量的交互操作即可得到比較好的分割結果。

            GrabCut,主要功能是分割前景和背景。
         1)你只需要在目標外面畫一​​個框,把目標框住,它就可以完成良好的分割:

  2)如果增加額外的用戶交互(利用標記來指定前背景),那麼效果就可以更完美:

缺點
1.          如果背景比較複  雜或者背景和目標相似度很大,那分割就不太好了
2.          速度有點慢。

             GrabCut 函式定義
void grabCut(InputArray img, InputOutputArray mask, Rect rect,
                             InputOutputArray bgdModel, InputOutputArray fgdModel,
                             int iterCount, int mode=GC_EVAL )
            img:待分割的來源圖,必须是83通道(CV_8UC3)图像,在處理過程中不會被修改;
           mask:遮掩圖像,大小和原圖一致。可以有如下幾種參數:
                    GC_BGD=0),背景;
                    GC_FGD=1),前景;
                    GC_PR_BGD=2),可能的背景;
                    GC_PR_FGD=3),可能的前景。
             rect:限定需要進行分割的圖像範圍,只有該矩形內部可以進行處理
             bgdModel:背景模型,如果為null,函数内部會自己創建一個bgdModel(背景模組)
             fgdModel:前景模型,如果為null,函数内部會自己創建一個fgdModel(前景模組)
             iterCount:迭代次數,必须大於0(越高分越準,但會影響處理時間)
             mode:用於指示grabCut函式進行什麼操作。可以有如下幾種選擇:
                    GC_INIT_WITH_RECT=0),用矩形窗初始化GrabCut
                    GC_INIT_WITH_MASK=1),用被遮蓋的圖初始化GrabCut








2016年1月19日 星期二

[Android] Usb debug can't find device

因為換了一台新電腦,然後發現我在用 USB進行 DEBUG 時候,一直沒罷法抓到裝置,後來發現是因為新電腦沒辦法抓到新的 Driver



[解決方法] Make your own driver

       1.Go to Dedevice manager and find the hardware id code(先到裝置找到硬體描述碼)
              


     2.Go to this path to rewrite this file ( 修改這份資料)
              \Android\android-sdk\extras\google\usb_driver\android_winusb.inf  


     3.Write down the following below  [Google.NTx86] or  [Google.NTamd64]
         (在 [Google.NTx86] 底下,或是 [Google.NTamd64]  底下加入兩行)

                        ;Samsung S3
                       %CompositeAdbInterface%     = USB_Install, USB\VID_04E8&PID_6860&MI_03

                         ps:Samsung S3 隨便取    USB\VID_04E8&PID_6860&MI_03 硬體碼部分

    4.Renew the Driver (更新驅動)

    5.Choose the file path.(選擇位置)
                                        
\

   6.Everything has done!!


    ˋ


        

2015年12月24日 星期四

[Project-web]Front end web final project

這是一堂網頁設計的期末專題
雖然老師進度緩慢,但是我從零到有,並偷懶從bootstrap開始學起,從中真的學到非常多的東西,像是html 相關標籤語言,利用css來達成美化和版面配置,最後一些滑動點擊事件處理利用jQuery,很開心完成自己從以前就想學習怎麼實作的想法,感謝自己有勇氣修這堂課.

This is my web design courses final project.
In this part we are going to show the front end part.Although teacher taught in a slow way, I learn how to use bootstrap by making my web!!
From zero to 100%.It's really a fantastic thing!!!!


2015年11月26日 星期四

[Android] EditText close the default pop-out keyboard 關閉鍵盤自動跳出

Method: 
在AndroidMainfest.xml中把windowSoftInputMode把屬性設成
adjustUnspecified|stateHidden

Go to Mainfest.xml choose your activity and type android:windowSoftInputMode="adjustUnspecified|stateHidden"

< activity android:name=" .Main " 
android:label="@string/app_name" 
android:windowSoftInputMode="adjustUnspecified|stateHidden" > 
< intent-filter> 
< action android:name="android.intent.action.MAIN" /> 
< category android:name="android.intent.category.LAUNCHER" /> 
< /intent-filter> 
< /activity>  

2015年11月17日 星期二

[OpenCV C++]Load Image 圖片開啟

cvLoadImage()

載入圖片的意思 IplImage* cvLoadImage("檔案名稱",參數); 參數的部份可以參考命名規則的說明,回傳的訊息是IplImage資料結構,它的參數分類有 #define CV_LOAD_IMAGE_UNCHANGED -1 原圖影像 #define CV_LOAD_IMAGE_GRAYSCALE 0 灰階 #define CV_LOAD_IMAGE_COLOR 1 彩色 #define CV_LOAD_IMAGE_ANYDEPTH 2 任何彩度 #define CV_LOAD_IMAGE_ANYCOLOR 4 任何彩色

cvNamedWindow()

cvNamedWindow("視窗名稱",參數);
而它的參數實質上只有一個
AUTOSIZE可以讓圖片便成原圖大小,也就是圖形維度不做調整,但是圖片太大很容易造成困擾
如果要微調就要用到cvResizeWindow()這個函式
但是,cvNamedWindow()不能設成1(CV_WINDOW_AUTOSIZE),務必將參數設為0或其他非1的數字.

#include < opencv2/core/core.hpp >
#include < opencv2/highgui/highgui.hpp >
#include < iostream >
using namespace cv;
using namespace std;
int main()
{
    IplImage *InImage;

 InImage = cvLoadImage("C:/Users/Public/Pictures/Sample Pictures/789.jpg",CV_LOAD_IMAGE_GRAYSCALE);
    
 CvSize Size1 = cvGetSize(InImage);

    //建立視窗(視窗名稱,參數)
 cvNamedWindow("InImage",CV_WINDOW_AUTOSIZE);
 
    //顯示影像(視窗名稱,影像檔案)
    cvShowImage("InImage",InImage);
  
    cvWaitKey(0); //按下任意按鍵可將圖片關閉
 cvReleaseImage(&InImage); //釋放來源影像佔用的記憶體
    cvDestroyWindow( "InImage" ); //銷毀視窗「src」
    return 0;

  
}

2015年10月29日 星期四

[Eclispe]加上自動提示(Intellisense)程式碼

When u build an new environment!!! Don't forget to set Eclipse Intellisense. it will help u a lot haha!!

打一打沒有提示字真得好難,這次來分享自動提示

Solution:
Windows -> Preferences -> Java -> Editor -> Content Assist
Auto activation triggers for Java keyin                    abcdefghijklmnopqrstuvwxyz(,


[Eclipse] console font size

Sometime i will forget how to resize my console font size in my eclipse!!

Solution
window -> preferences-> general -> appearance -> colors and fonts ->debug -> console font 


【Android】Redering Problems Missing Styles

After i update my Android Studio , my XML always show  Rendering Problems Missing Style
今天在升級版的Android Studio後,在建立新應用程式後,都會出現下列的問題畫面:


Solution:

【File】→【Invalidate Caches / Restart...】:

[Android] java.io.FileNotFoundException AND android.os.NetworkOnMainThreadException!!

1.Android 4.0 has a new Exception in NetWork part.So if you request it.
You will get a android.os.NetworkOnMainThreadException!!

Android4.0在網路的部份多了一個新的Exception,
叫做android.os.NetworkOnMainThreadException
意思就是說:網路的活動跑在主要執行緒上了,很貼心的告訴你,這樣子你的APP可能會因為網路的活動等待回應太久,而被系統強制關閉(收到ANR)。

Solution:(put it in main )
StrictMode
    .setThreadPolicy(new StrictMode.ThreadPolicy.Builder()  
    .detectDiskReads()  
    .detectDiskWrites()  
    .detectNetwork()   // or .detectAll() for all detectable problems  
    .penaltyLog()  
    .build());  



2.Android 4.0 hope developer use post to request ,But if will occur
Java.io.FileNotFoundException

4.0中設置httpCon.setDoOutput(true),将導致請求以post方式提交
然後就會出現 java.io.FileNotFoundException

Soluation:
Delete-->httpCon.setDoOutput(true);

2015年8月29日 星期六

[C++]VECTOR ALLOCATION

Basis

Define:vector<int> array;

Two dynamic vector +initialize  0:

vector<vector<int> > array;
array.resize(y, vector<int>(x, 0));

OR

vector<vector<int> > array(y, vector<int>(x, 0));
**
vector<vector<int> > array(y, vector<int>(x));//ALSO '0'


2015年7月26日 星期日

【Eclipse] 中文出現亂碼 gibberish in chinese character

有時候import project的時候,就會出現中文亂碼#%$#%一整個很困擾
Sometime i import a project the chinese character all become %$#$%# !!!!
IT'S VERY NOISY!!!!! 

 SOLVE METHOD
 Step 1. 「Window」->「Preferences」
 Step 2. 「General」->「Workspace」。
 Step 3. 「Text file encoding」 Change Default (MS950) ->「UTF-8」。
 Step 4. Press 「Apply」

[Android] 通知(Notification)

Take a note !! so next time if i use notification it will become faster :")) 
新(New):Notification.Builder來快速產生出來
NotificationManager notificationManager = (NotificationManager) getSystemService(NOTIFICATION_SERVICE );
Builder builder = new Notification.Builder(Update.this );
PendingIntent contentIndent = PendingIntent.getActivity(Update. this, 0, new Intent(Update.this , Update. class),PendingIntent. FLAG_UPDATE_CURRENT);
builder.setContentIntent(contentIndent)
       .setSmallIcon(R.drawable.icon) // 設置狀態列裡面的圖示          
       .setTicker("New Message") // 設置狀態列的顯示的資訊
       .setWhen(System. currentTimeMillis()) // 設置發生時間
       .setContentTitle( "I-Calories計算結果通知" )//設置通知清單裡的標題
       .setContentText("共消耗"+ca); // 設置內容
							  
Notification notification = builder.getNotification();
notificationManager.notify(1, notification);
設定預設提示音(notification.defaults to set default alarm ring)
notification.defaults |= Notification.DEFAULT_SOUND;//預設鈴聲
相關連結(good learning website) 更詳細可以點及這個很棒的網站作更深入的學習 http://magiclen.org/android-notifications/ 
http://www.codedata.com.tw/mobile/android-tutorial-the-5th-class-2-notificationhttp://givemepass.blogspot.tw/2011/11/notification.html 
http://blog.maxkit.com.tw/2014/03/android-notification.html

[Android] Vibrate 振動實作

Sometime we need to let the phone vibrate when receive a message or something happen
我們現在來進行實做 "振動" 這項功能
  Vibrator myVibrator = (Vibrator) getApplication().getSystemService(Service.VIBRATOR_SERVICE);
  myVibrator.vibrate(1000);//millisecond

Don't forget to add in your AndroidManifest.xml!!!!!
<uses-permission android:name="android.permission.VIBRATE" />

[Android] Toast

We have two method to use Toast 我們有兩種方式來顯示Toast

1.ToastActivity.this depends on this class name
 Toast toast = Toast.makeText(ToastActivity.this,"Hello world!", Toast.LENGTH_LONG);
 toast.show();
2.getApplicationContext()to get Current Context
 Context context1 = getApplication();
 Toast.makeText(context2, "Hello world!", Toast.LENGTH_LONG).show();

2015年6月8日 星期一

Android-finished with non-zero exit value 1

I encounted a problem in android studio. it shows ".....finished with non-zero exit value 1"
all my R.~~has a red underline!!! 
i was really shock!!!

Solution:
I cleaned the project and solved

Reason:
I faced this issue after replacing png drawables with jpg with the same name

2015年5月31日 星期日

Google Glass - 'Jump' to a card in CardScrollView via setSelection doesnt work

I had found why it can't jump to specific card for 1~2days.
Finally i got a resolution. hope i could help others
This block is get the position and use animate to jump to the specific
 mCardScroller.setSelection(mCardScroller.getSelectedItemPosition() + 1);
 mCardScroller.startAnimation(AnimationUtils.makeInAnimation(mCardScroller.getContext(), true));
BUT!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! NOT WORK
IMPORTANT!!ADD THIS IN YOUR ONCREATE()
mCardScroller.activate()
AND CHECK THIS TWO LIFE PERIOD
@Override
    protected void onResume() {
        super.onResume();
        mCardScroller.activate();
    }

    @Override
    protected void onPause() {
        mCardScroller.deactivate();
        super.onPause();
    }
GOOGLE GLASS 跳到特定的CARD,如果你咬遇到一樣的問題setSelection始終無法使用,在ONCREATE()理面加入mCardScroller.activate()就會有結果了 希望可以幫住到更多人,因為GLASS的資訊好少,我們也花了一點時間來解決這個問題!!

2015年5月29日 星期五

[mySQL]hinet.net is not allow to connect to this mySQL server

When i tried to connect mySql (not localhost),i met a problem






[Solution]:Because other the authority
shell>mysql --user=root -p
輸入密碼
mysql>use mysql
mysql>GRANT SELECT,INSERT,UPDATE,DELETE ON [db_name].* TO [username]@[ipadd] identified by '[password]';

[username]:遠程登入的使用者代碼(userid)
〔db_name]:表示欲開放給使用者的數據庫稱(show for user db name)
[password]:遠程登入的使用者密碼(user pwd)
[ipadd]:IP地址或者IP反查後的DNS Name,此例的內容需填入'59-126-182-81.HINET-IP.hinet.net',包涵上引號(')

(其實就是在遠端服務器上執行,地址填寫本地主機的ip地址。)

2015年5月22日 星期五

C# Textbox automatically scroll to the bottom

If you try to show the text on your textbox,we will account a problem.
The textbox vertical or horizontal length is not enough for us to use.
LIKE THIS PICRURE BELOW



















Solution:
  textBox1.ScrollBars = ScrollBars.Vertical; //scroll in vertical 
  textBox1.Text +=count+" : "+ read.GetInt32(0) + "Data"+"\r\n";
  textBox1.SelectionStart = textBox1.Text.Length;
  textBox1.ScrollToCaret();
  textBox1.Refresh();






2015年5月19日 星期二

C++ Fixed decimal point

Record how to fix the decimal point in c++
int main(){
 long double o = sqrt(2);
 for(int i = 0 ; i < 20 ; i++){//print long double
        cout.precision(i);
        cout << o << endl;
    }
}
1
1.4
1.41
1.414
1.4142
1.41421
1.414214
1.4142136
1.41421356
1.414213562
1.4142135624
1.41421356237
1.414213562373
1.4142135623731
1.41421356237310
1.414213562373095
1.4142135623730951
1.41421356237309510
1.414213562373095100
1.4142135623730951000

2015年5月15日 星期五

C++ Vector

Record c++ Vector otherwise i will forget~~
First #include<vector>

"Add element"
for(int i=0 ; i<10 ; i++){
     cout<<"Add "<< i<<" to vector"<< endl;
     v1.push_back(i);
}
     cout<<"size : "<< v1.size()<< endl;

"Resize"
v1.resize(8);
cout<<"resize :"<< v1.size()<< endl;
cout<<"resize element :"<< endl;
for(int i=0 ; i < v1.size() ; i++){
cout<<"NO "<< i+1<<" : "<< v.1[i]<<"  "<< endl;
}

"Delete element"
int pos;
cout<<"Delete NO ";
cin>>pos;
v1.erase(v1.begin()+(pos-1));//begin=起始+0
for(int i=0 ; i < v1.size() ; i++)
cout<<"NO "<< i+1<<" : "<< v1[i]<< endl;

"Pop top element"
cout<<"pop top "<< endl;
v1.pop_back();
for(int i=0 ; i < v1.size() ; i++)
cout<<"NO "<< i+1<<" : "<< v1[i]<<"  "<< endl;

"Sort"
sort(v1.begin(),v1.end());
for(int i=0 ; i < v1.size() ; i++)
cout<< v1[i]<<" ";
cout<< endl;

"Reverse element"
cout<<"reverse : ";
reverse(v1.begin() , v1.end());
for(int i=0 ; i < v1.size() ; i++)
cout << v1[i]<<"  ";
cout<< endl;

"Use iterator"
cout<<"Find value : ";
int fnum;
cin>>fnum;
vector< int >::iterator it;
it=find(v1.begin() , v1.end() , fnum);
  if(it != v1.end()) {
     cout << "Found value!" << endl;
  }
  else{
      cout << "Not found!" << endl;
  }
cout<<"Use iterator"<< endl;
int count=0,temp;
for(it=v1.begin() ; it!=v1.end() ; it++){
     count++;
     cout<< *it <<" ";
       if(*it==fnum)
  temp=count;
}
 cout<< endl;
 cout<<"Found "<< fnum<<" position : "<< temp<< endl;

"Clean vector"
cout<<"use clear vector "<< endl;
v1.clear();
if(v1.empty())
   cout<<"empty vector"<< endl;
else
   cout<<"unempty"<< endl;

Some vector learning website:
web1
web2