caffe項目中自帶了一個classification.cpp文件,能夠用訓練好的模型進行直接分類,不過須要在caffe項目外使用的話就須要本身寫編譯代碼。html
能夠參考一下這篇文章,找了很久才找到http://blog.sina.com.cn/s/blog_534497fd0102wf2t.html 裏面寫的很全。而後根據這篇簡單總結了一下cmakelists.txt的簡單寫法python
cmake_minimum_required(VERSION 2.8) project(classification) find_package(OpenCV REQUIRED) find_package(Caffe REQUIRED) include_directories( ${Caffe_INCLUDE_DIRS} ) add_definitions(${Caffe_DEFINITIONS}) # ex. -DCPU_ONLY add_executable(caffeClassify classification.cpp) target_link_libraries(caffeClassify ${OpenCV_LIBS} ${Caffe_LIBRARIES})
若是要在qt中使用的話推薦一下這個https://github.com/withwsf/Image_detection/blob/master/Image_detection.pro,裏面有用qt管理的caffe項目,我把他的.pro複製出來。c++
QT += core gui CONFIG +=c++11 greaterThan(QT_MAJOR_VERSION, 4): QT += widgets TARGET = Image_detection TEMPLATE = app SOURCES += main.cpp\ mainwindow.cpp \ image_detection.cpp \ nms.cpp \ dockwidget.cpp \ detector_warpper.cpp HEADERS += mainwindow.h \ image_detection.h \ nms.h \ dockwidget.h \ detector_warpper.h FORMS += mainwindow.ui \ dockwidget.ui INCLUDEPATH += /home/vcc/caffe_depen/caffe-fast-rcnn/include \ /usr/include/opencv /usr/include/opencv2 \ LIBS += -L/home/vcc/caffe_depen/lib -lcaffe -lcblas -latlas LIBS+= -L/usr/local/lib -lglog -lgflags -lprotobuf -lleveldb -lsnappy -llmdb -lboost_system -lhdf5_hl -lhdf5 -lm -lopencv_core -lopencv_highgui -lopencv_imgproc -lboost_thread -lstdc++ -lprotobuf INCLUDEPATH +=/usr/include/python2.7/ INCLUDEPATH +=/usr/include/ LIBS += -lboost_python -lpython2.7 -lboost_system
這是這個做者的工程,能夠借鑑着改。git
想要在windows中使用caffe項目,推薦這個githubhttps://github.com/happynear/caffe-windows/tree/ms到這個目錄中https://github.com/happynear/caffe-windows/tree/ms/windows/caffe.binding,你們也能夠借鑑着改。github