使用MinGW編譯Efficient graph-based image segmentation

1. 首先下載MinGW-w64[1],一路安裝下來,並不知道是否設置了環境變量:


編寫一個簡單的程序實驗一下,同時用cmd命令重新開了一個窗口,也可以運行出結果:


2. 編譯Efficient graph-based image segmentation

根據其提供的Makefile:

INCDIR = -I.
DBG    = -g
OPT    = -O3
CPP    = g++
CFLAGS = $(DBG) $(OPT) $(INCDIR)
LINK   = -lm 

.cpp.o:
	$(CPP) $(CFLAGS) -c $< -o $@

all: segment

segment: segment.cpp segment-image.h segment-graph.h disjoint-set.h
	$(CPP) $(CFLAGS) -o segment segment.cpp $(LINK)

clean:
	/bin/rm -f segment *.o

clean-all: clean
	/bin/rm -f *~ 
在mingw-w64打開的窗口中編譯,會出現下面的錯誤,其中g++的參數命令意義參考[3]


而打開segment-image.h中引用了頭文件<cstdlib>,但根據[2]中該頭文件裏面只定義了rand隨機數,並沒有定義random,不知道這個是否在Linux下就有呢?所以需要在segment-image.h中將random換成rand。然後再次編譯就成功了。

但這一次如果將這個segment.exe拖到cmd的窗口裏面就出現了下面的錯誤,這個就說明剛纔的MinGW安裝並沒有全局添加環境變量,臨時的環境變量添加參考[4]


3. 在Matlab調用的代碼:

prefix = num2str(floor(rand(1)*10000000));
fn1 = ['./tmpim' prefix '.ppm'];
fn2 = ['./tmpimsp' prefix '.ppm'];
setenv('PATH', [getenv('PATH') ';D:\Programs\mingw-w64\i686-5.2.0-posix-dwarf-rt_v4-rev0\mingw32\bin']);
segcmd = 'E:\code\download\segment\segment 0.8 100 100';

imwrite(im, fn1);
system([segcmd ' ' fn1 ' ' fn2]);



參考:

【1】http://sourceforge.net/projects/mingw-w64/

【2】http://www.cplusplus.com/reference/cstdlib/

【3】GCC/G++編譯參數含義 http://blog.csdn.net/zhuxiaoyang2000/article/details/5575194

【4】MinGw以及臨時加路徑 http://blog.csdn.net/lsxpu/article/details/43228607

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章