読者です 読者をやめる 読者になる 読者になる

OpenCV 2.1の関数 CとC++の対照表 (未完)

OpenCVの関数の利用は、これから徐々にC形式からC++形式へと移行していく感じがします。今までC形式の関数に慣れ親しんだ人がC++でやろうとしたとき、大抵は関数の名前が似ていてすぐわかるのですが、全然違うものもあり、そもそも対応するものが無かったりもして、混乱します。

Twitterでなんとなく「対照表あったらいいなあ」とつぶやいたら意外と反響があったので、作ってみます。大きく違いがあるものだけ載せてもいいのですが、とにかく全部載せて、違いが大きいものは太字にしています。「リファレンス見ると無さそうだけど、ヘッダ見たら有った」ということが多いので。

当分は未完ですが、気付き次第・気力がたまり次第追加していくつもりです。そもそも普段OpenCVをCからもC++からも使ってはいない身には無謀な事業ですが、間違いがあればお知らせ下さるとありがたいです。

cv

C C++ 備考
cvCopyMakeBorder cv::copyMakeBorder
cvSmooth cv::medianBlur, cv::GaussianBlur, cv::bilateralFilter (, cv::boxFilter, cv::blur)
? cv::boxFilter
cvFilter2D cv::filter2D
? cv::sepFilter2D
cvIntegral cv::integral
cvPyrDown cv::pyrDown
cvPyrUp cv::pyrUp
cvCreatePyramid cv::buildPyramid ? 全然違う気が...
cvPyrSegmentation ?
cvPyrMeanShiftFiltering ?
cvWatershed cv::watershed
cvInpaint cv::inpaint
? cv::grabCut
cvSobel cv::Sobel
cvSobel(src, dst, xorder, yorder, CV_SCHARR) cv::Scharr
cvLaplace cv::Laplacian
cvCanny cv::Canny
cvCvtColor cv::cvtColor
cvResize cv::resize
cvWarpAffine cv::warpAffine
cvGetAffineTransform cv::getAffineTransform
? cv::invertAffineTransform
cv2DRotationMatrix cv::getRotationMatrix2D
cvWarpPerspective cv::warpPerspective
cvGetPerspectiveTransform cv::getPerspectiveTransform
cvRemap cv::remap
cvConvertMaps cv::convertMaps
cvLogPolar ?
cvLinearPolar ?
IplConvKernel ? cv::Matで指定するらしい
cvErode cv::erode
cvDilate cv::dilate
cvMorphologyEx cv::morphologyEx
CvMoments cv::Moments
cvMoments cv::moments
cvGetSpatialMoment ? CvMomentsに比べてcv::Momentsはメンバが増えてるから、その辺で何とかするのかな?
cvGetCentralMoment ?
cvGetNormalizedCentralMoment ?
cvGetHuMoments cv::HuMoments
C C++ 備考
cvSampleLine ?
cvGetRectSubPix cv::getRectSubPix
cvGetQuadrangleSubPix ?
cvMatchTemplate cv::matchTemplate
cvCalcEMD2 ?
C C++ 備考
cvFindContours cv::findContours
cvDrawContours cv::drawContours CではcxcoreにあるがC++ではcvにある
CvContourScanner ?
cvApproxChains ?
CvChainPtReader ?
C C++ 備考
cvCalcOpticalFlowLK ?
cvCalcOpticalFlowBM ?
cvCalcOpticalFlowHS ?
cvCalcOpticalFlowPyrLK cv::calcOpticalFlowPyrLK
cvCalcAffineFlowPyrLK ?
cvEstimateRigidTransform ?
cvCalcOpticalFlowFarneback cv::calcOpticalFlowFarneback
C C++ 備考
cvUpdateMotionHistory cv::updateMotionHistory
cvCalcMotionGradient cv::calcMotionGradient
cvCalcGlobalOrientation cv::calcGlobalOrientation
cvSegmentMotion ?
C C++ 備考
cvAcc cv::accumulate
cvSquareAcc cv::accumulateSquare
cvMultiplyAcc cv::accumulateProduct
cvRunningAvg cv::accumulateWeighted
C C++ 備考
cvCamShift cv::CamShift
cvMeanShift cv::meanShift
? cv::estimateAffine3D
CvKalman cv::KalmanFilter
cvKalmanPredict KalmanFilter::predict
cvKalmanCorrect KalmanFilter::correct
C C++ 備考
cvUndistort2 cv::undistort
cvInitUndistortMap ?
cvInitUndistortRectifyMap cv::initUndistortRectifyMap
cvUndistortPoints cv::undistortPoints
cvGetOptimalNewCameraMatrix cv::getOptimalNewCameraMatrix
? cv::getDefaultNewCameraMatrix
cvRodrigues2 cv::Rodrigues
cvFindHomography cv::findHomography
cvRQDecomp3x3 cv::RQDecomp3x3
cvDecomposeProjectionMatrix cv::decomposeProjectionMatrix
cvCalcMatMulDeriv cv::matMulDeriv
cvComposeRT cv::composeRT
cvProjectPoints2 cv::projectPoints
cvFindExtrinsicCameraParams2 cv::solvePnP
cvInitIntrinsicParams2D cv::initCameraMatrix2D
cvCheckChessboard ?
cvFindChessboardCorners cv::findChessboardCorners
cvDrawChessboardCorners cv::drawChessboardCorners
cvCalibrateCamera2 cv::calibrateCamera
cvCalibrationMatrixValues cv::calibrationMatrixValues
cvStereoCalibrate cv::stereoCalibrate
cvStereoRectify cv::stereoRectify
cvStereoRectifyUncalibrated cv::stereoRectifyUncalibrated
? cv::rectify3Collinear OpenCV2.2
cvPOSIT ?
cvRANSACUpdateNumIters ?
cvConvertPointsHomogeneous cv::convertPointsHomogeneous
cvFindFundamentalMat cv::findFundamentalMat
cvComputeCorrespondEpilines cv::computeCorrespondEpilines
cvTriangulatePoints ?
cvCorrectMatches ?
cvFindStereoCorrespondenceBM cv::StereoBM
? cv::filterSpeckles
cvGetValidDisparityROI cv::getValidDisparityROI
cvValidateDisparity cv::validateDisparity
cvFindStereoCorrespondenceGC ?
cvReprojectImageTo3D cv::reprojectImageTo3D
? cv::StereoSGBM
cvExtractSURF cv::SURF
cvExtractMSER cv::MSER
cvGetStarKeypoints cv::StarDetector

cxcore

C C++ 備考
CvMat, IplImage cv::Mat
cvGetRow Mat::row
cvGetCol Mat::col
cvGetRows Mat::rowRange
cvGetCols Mat::colRange
cvGetDiag Mat::diag
cvCloneMat Mat::clone
cvCopy Mat::copyTo
cvConvertScale Mat::convertTo
cvConvert, (cvConvertScale) Mat::assignTo
cvSet Mat::operator = (const Scalar&)
cvSet Mat::setTo
cvReshape Mat::reshape
cvCrossProduct Mat::cross
cvDotProduct Mat::dot
(cvSetZero) Mat::zeros
(cvSet(cvmat, cvScalarAll(1))) Mat::ones
(cvSetIdentity) Mat::eye
cvGetImageROI? Mat::locateROI
cvSetImageROI? Mat::adjustROI
cvGetSubRect Mat::operator()(Range, Range)
CV_IS_MAT_CONT(cvmat->type) Mat::isContinuous
CV_ELEM_SIZE(cvmat->type) Mat::elemSize
CV_ELEM_SIZE1(cvmat->type) Mat::elemSize1
CV_MAT_TYPE(cvmat->type), cvGetElemType Mat::type
CV_MAT_DEPTH(cvmat->type) Mat::depth
CV_MAT_CN(cvmat->type) Mat::channels
(step/elemSize1) Mat::step1
cvGetSize Mat::size
!CV_IS_MAT(cvmat) Mat::empty
cvPtr*D Mat::ptr
cvGet2D, cvSet2D, cvmGet, cvmSet, CV_MAT_ELEM Mat::at
cvGetMat Mat::operator CvMat
cvGetImage Mat::operator IplImage
cvRepeat cv::repeat
cvSetData ?
cvGetRawData ?
cvSplit cv::split
cvMerge cv::merge
cvMixChannels cv::mixChannels
cvConvertScaleAbs cv::convertScaleAbs
cvCheckTermCriteria ?
C C++ 備考
cvAdd, cvAddS cv::add
cvSub, cvSubS, cvSubRS cv::subtract
cvMul cv::multiply
cvDiv cv::divide
cvScaleAdd cv::scaleAdd
cvAddWeighted cv::addWeighted
cvAnd, cvAndS cv::bitwise_and
cvOr, cvOrS cv::bitwise_or
cvXor, cvXorS cv::bitwise_xor
cvNot cv::bitwise_not
cvInRange, cvInRangeS cv::inRange
cvCmp, cvCmpS cv::compare
cvMin, cvMinS cv::min
cvMax, cvMaxS cv::max
cvAbsDiff, cvAbsDiffS cv::absdiff
C C++ 備考
cvCartToPolar cv::cartToPolar
cvPolarToCart cv::polarToCart
? cv::phase
? cv::sqrt
cvPow cv::pow
cvExp cv::exp
cvLog cv::log
cvFastArctan cv::fastAtan2
cvCbrt cv::cubeRoot
cvCheckArr cv::checkRange
cvRandArr cv::RNG::fill
cvRandShuffle cv::randShuffle
cvSort cv::sort
? cv::sortIdx
cvSolveCubic cv::solveCubic
cvSolvePoly cv::solvePoly
C C++ 備考
cvGEMM cv::gemm
cvTransform cv::transform
cvPerspectiveTransform cv::perspectiveTransform
cvMulTransposed cv::mulTransposed
cvTranspose cv::transpose
cvCompleteSymm cv::completeSymm
cvFlip cv::flip
cvSVD cv::SVD
cvSVBkSb cv::SVD::backSubst
cvInvert cv::invert
cvSolve cv::solve
cvDet cv::determinant
cvTrace cv::trace
cvEigenVV cv::eigen
cvSetIdentity cv::setIdentity
cvRange ?
cvCalcCovarMatrix cv::calcCovarMatrix
cvCalcPCA cv::PCA
cvProjectPCA cv::PCA::project
cvBackProjectPCA cv::PCA::backProject
cvMahalanobis cv::Mahalanobis
C C++ 備考
cvSum cv::sum
cvCountNonZero cv::countNonZero
cvAvg cv::mean
cvAvgSdv cv::meanStdDev
cvMinMaxLoc cv::minMaxLoc
cvNorm cv::norm
cvNormalize cv::normalize
cvReduce cv::reduce
C C++ 備考
cvDFT cv::dft
cvDFT(src, dst, CV_DXT_INVERSE) cv::idft
cvMulSpectrums cv::mulSpectrums
cvGetOptimalDFTSize cv::getOptimalDFTSize
cvDCT cv::dct
cvDCT(src, dst, CV_DXT_INVERSE) cv::idct
C C++ 備考
CvMemStorage cv::MemStorage (cv::Ptr<CvMemStorage>)
CvSeq template<typename _Tp> cv::Seq vectorに取って代わられたのでもうあまり出番はなさそう
seq->total Seq<_Tp>::size
cvSliceLength ?
cvSetSeqBlockSize ?
cvSeqPush Seq<_Tp>::push_back
cvSeqPushFront Seq<_Tp>::push_front
cvSeqPop Seq<_Tp>::pop_back
cvSeqPopFront Seq<_Tp>::pop_front
cvSeqPushMulti Seq<_Tp>::push_front/push_back(_Tp*, size_t)
cvSeqPopMulti Seq<_Tp>::pop_front/pop_back(_Tp*, size_t)
cvSeqInsert Seq<_Tp>::insert
cvSeqRemove Seq<_Tp>::remove
cvClearSeq Seq<_Tp>::clear
cvGetSeqElem Seq<_Tp>::operator[](int)
cvSeqElemIdx Seq<_Tp>::index
CvSeqWriter ?
CvSeqReader template<typename _Tp> cv::SeqIterator
cvGetSeqReaderPos SeqIterator<_Tp>::tell ?
cvSetSeqReaderPos SeqIterator<_Tp>::seek
cvCvtSeqToArray Seq<_Tp>::copyTo, Seq<_Tp>::operator vector<_Tp>
cvMakeSeqHeaderForArray ?
cvSeqSlice ?
cvCloneSeq ?
cvSeqRemoveSlice ?
cvSeqInsertSlice ?
cvSeqSort ?
cvSeqSearch ?
cvSeqInvert ?
cvSeqPartition ?
C C++ 備考
CV_RGB(r, g, b) cv::Scalar::Scalar(b, g, r) RGB順は無い?
cvLine cv::line
cvRectangle cv::rectangle(cv::Mat&, cv::Point, cv::Point, ...)
cvRectangleR cv::rectangle(cv::Mat&, cv::Rect, ...)
cvCircle cv::circle
cvEllipse cv::ellipse(cv::Mat&, cv::Point, cv::Size, double, double, double, ...)
cvEllipseBox cv::ellipse(Mat&, const RotatedRect&, ...)
cvFillConvexPoly cv::fillConvexPoly
cvFillPoly cv::fillPoly
cvPolyLine cv::polylines
cvClipLine cv::clipLine
CvLineIterator cv::LineIterator
CV_NEXT_LINE_POINT cv::LineIterator::operator ++
CvFont ? cv::putText ではフォントの情報を別々の引数で指定するようになっているから無くなったらしい
cvPutText cv::putText
cvGetTextSize cv::getTextSize
cvColorToScalar ?
cvEllipse2Poly cv::ellipse2Poly
cvLUT cv::LUT
cvKMeans2 cv::kmeans

highgui

2.1時点ではずいぶん貧弱ですが、SVN版ではもう少し補われているほか、かなり色々と追加されています。

C C++ 備考
cvInitSystem ?
cvStartWindowThread ?
cvNamedWindow cv::namedWindow
cvSetWindowProperty cv::setWindowProperty
cvGetWindowProperty cv::getWindowProperty
cvShowImage cv::imshow
cvResizeWindow ?
cvMoveWindow ?
cvDestroyWindow ?
cvDestroyAllWindows ?
cvGetWindowHandle ?
cvGetWindowName ?
cvCreateTrackbar (cv::createTrackbar)
cvCreateTrackbar2 cv::createTrackbar
cvGetTrackbarPos cv::getTrackbarPos
cvSetTrackbarPos cv::setTrackbarPos
cvSetMouseCallback ?
cvLoadImage, cvLoadImageM cv::imread
cvSaveImage cv::imwrite
cvDecodeImage, cvDecodeImageM cv::imdecode
cvEncodeImage cv::imencode
cvConvertImage ?
cvWaitKey cv::waitKey
C C++ 備考
CvCapture cv::VideoCapture
cvCreateFileCapture VideoCapture::VideoCapture(const string&)
cvCreateCameraCapture VideoCapture::VideoCapture(int)
cvGrabFrame VideoCapture::grab
cvRetrieveFrame VideoCapture::retrieve
cvQueryFrame VideoCapture::operator >>
cvGetCaptureProperty VideoCapture::get
cvSetCaptureProperty VideoCapture::set
cvGetCaptureDomain ?
CvVideoWriter cv::VideoWriter
cvCreateVideoWriter VideoWriter::VideoWriter, VideoWriter::open
cvWriteFrame VideoWriter::operator <<