Skip to content

Instantly share code, notes, and snippets.

@kjunichi
Last active December 26, 2017 04:10
Show Gist options
  • Save kjunichi/8015345 to your computer and use it in GitHub Desktop.
Save kjunichi/8015345 to your computer and use it in GitHub Desktop.
OpenCVのメモ

C++ API

cv::Mat同士の比較

cv::calcHist cv::compareHist

画像の切出し

顔検出された部分を切出すには

cap >> frame;

cv::Mat roi(frame, cv::Rect(cvRound(r.x*(1/fx)), cvRound(r.y*(1/fx)),
  cvRound(r.width*(1/fx)), cvRound((r.height)*(1/fx))));

各種言語で使う

QTKitはどうなった

2.4.9現在、QTKitを使っていた。otoolで確認。

どこかで、Makefile的なところで、Mavericksあたりから分岐でAVFoundationのコードを読むようになったのを 見かけた気がするが。

# --- Apple AV Foundation ---
if(WITH_AVFOUNDATION)
set(HAVE_AVFOUNDATION YES)
endif()
# --- QuickTime ---
if (NOT IOS)
if(WITH_QUICKTIME)
set(HAVE_QUICKTIME YES)
elseif(APPLE AND CMAKE_COMPILER_IS_CLANGCXX)
set(HAVE_QTKIT YES)
endif()
endif()
if(HAVE_AVFOUNDATION)
list(APPEND videoio_srcs ${CMAKE_CURRENT_LIST_DIR}/src/cap_avfoundation.mm)
list(APPEND VIDEOIO_LIBRARIES "-framework AVFoundation" "-framework QuartzCore")
endif()
if(HAVE_QUICKTIME)
list(APPEND videoio_srcs ${CMAKE_CURRENT_LIST_DIR}/src/cap_qt.cpp)
list(APPEND VIDEOIO_LIBRARIES "-framework Carbon" "-framework QuickTime" "-framework CoreFoundation" "-framework QuartzCore")
elseif(HAVE_QTKIT)
list(APPEND videoio_srcs ${CMAKE_CURRENT_LIST_DIR}/src/cap_qtkit.mm)
list(APPEND VIDEOIO_LIBRARIES "-framework QTKit" "-framework QuartzCore" "-framework AppKit")
endif()

MatとIplImage

  • C++ではキャストでOK
  • CではCvMat

IplImageは1.0の頃からある構造体。WebCamのAPIがこの型で返す。

CのAPIを使う分には、CvArr*で各関数の引数が定義されているようなので、 変換する場面は無いのかも。

C API

cvCreateMemStorage

cvLoad

The function loads an object from a file. It basically reads the specified file, 
find the first top-level node and calls Read() for that node. 
If the file node does not have type information or the type information
 can not be found by the type name, the function returns NULL. After the object is loaded, 
the file storage is closed and all the temporary buffers are deleted. 
Thus, to load a dynamic structure, such as a sequence, contour, or graph, 
one should pass a valid memory storage destination to the function.

cvHaarDetectObjects

顔検出関連

cvLoadで学習データらしきxmlを読み込んでる

用語

  • 段階分類器

Link

WebCam

必要なAPI

  • cvCreateCameraCapture
  • cvNamedWindow
  • cvQueryFrame cvCreateCameraCaptureで取得したキャプチャオブジェクトを指定
  • cvShowImage cvQueryFrameで取得したイメージを表示する
  • cvWaitKey whileループで使うことで、ESCキー等の押下で終了を実現

Link

関連投稿

関連記事

関連

アクセス解析タグ

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment