openCV cv :: Matを使用する場合。http://docs.opencv.org/modules/core/doc/basic_structures.htmlある種のスマートポインターが使用されていることを理解しています。私の質問は、メモリの最適化を行うためです。
未使用の行列を解放するためにcv :: Mat release()を呼び出す必要がありますか?
または、コンパイラがそれを行うことを信頼する必要がありますか?
たとえば、次のコードについて考えてみます。
cv::Mat filterContours = cv::Mat::zeros(bwImg.size(),CV_8UC3);
bwImg.release();
for (int i = 0; i < goodContours.size(); i++)
{
cv::RNG rng(12345);
cv::Scalar color = cv::Scalar( rng.uniform(0, 255), rng.uniform(0,255), rng.uniform(0,255) );
cv::drawContours(filterContours,goodContours,i,color,CV_FILLED);
}
/*% Fill any holes in the objects
bwImgLabeled = imfill(bwImgLabeled,'holes');*/
imageData = filterContours;
filterContours.release(); //should I call this line or not ?
このcv::release()
関数はメモリを解放します。メモリは、とにかくMatインスタンスのスコープの最後でデストラクタが処理します。したがって、投稿したコードスニペットで明示的に呼び出す必要はありません。必要になる場合の例は、マトリックスのサイズが同じループ内の異なる反復で変化する可能性がある場合です。
using namespace cv;
int i = 0;
Mat myMat;
while(i++ < relevantCounter )
{
myMat.create(sizeForThisIteration, CV_8UC1);
//Do some stuff where the size of Mat can vary in different iterations\\
mymat.release();
}
ここで、cv :: release()を使用すると、すべてのループでポインターを作成するオーバーヘッドからコンパイラーを節約できます。
この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。
侵害の場合は、連絡してください[email protected]
コメントを追加