OpenCV的SVM :: train_auto内存泄漏。它是库中的错误还是错误的用法?

时间:2015-08-06 08:34:25

标签: c++ opencv memory-leaks

我正在使用OpenCV的SVM,似乎在train_auto函数中存在内存泄漏。
我在Boost::Test环境中运行它,因为它会在运行时发现泄漏时警告用户。
当我注释掉train_auto行时,没有泄漏。

这是完整的代码:

#define BOOST_TEST_MODULE SomeTestModule
#include <boost\test\included\unit_test.hpp>
#include "opencv2\ml\ml.hpp"
#include "opencv/cv.h"

BOOST_AUTO_TEST_CASE(SomeTestname) 
{
    // Prepare matrix of class numbers (few ones, few zeros)
    cv::Mat classes = cv::Mat::ones(10, 1, CV_32FC1);
    cv::vconcat(classes, (cv::Mat::zeros(10, 1, CV_32FC1)), classes);
    // Prepare matrix of 2-d feature vectors (random :D )
    cv::Mat featureVectors(20, 2, CV_32FC1);
    cv::randu(featureVectors, -1, 1);

    // Set up SVM parameters
    CvSVMParams params;
    params.svm_type = CvSVM::C_SVC;
    params.kernel_type = CvSVM::LINEAR;
    params.term_crit = cvTermCriteria(CV_TERMCRIT_ITER, 100, 1e-6);

    // And do the training!
    CvSVM svm;
    svm.train_auto(featureVectors, classes, cv::Mat(), cv::Mat(), params);

}

输出(在运行Boost::Test可执行文件后)是:

Running 1 test case...

*** No errors detected
Detected memory leaks!
Dumping objects ->
{865} normal block at 0x00D4C6F8, 44 bytes long.
 Data: <        y  ?q   > CD CD CD CD F8 C6 D4 00 79 AD 9E 3F 71 19 D1 BF
{862} normal block at 0x00D4C750, 44 bytes long.
 Data: <            P   > CD CD CD CD CD CD CD CD CD CD CD CD 50 C7 D4 00
{859} normal block at 0x00D4C598, 44 bytes long.
 Data: <               ?> CD CD CD CD 98 C5 D4 00 B0 D2 AF D6 FF CB AE 3F
{856} normal block at 0x00D4C540, 44 bytes long.
 Data: <            @   > CD CD CD CD CD CD CD CD CD CD CD CD 40 C5 D4 00
{853} normal block at 0x00D4C4E8, 44 bytes long.
 Data: <        yY- 5   > CD CD CD CD E8 C4 D4 00 79 59 2D AC 35 E9 AF BF
{850} normal block at 0x00D4C1D0, 44 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD D0 C1 D4 00
{847} normal block at 0x00D4C490, 44 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD 90 C4 D4 00
{844} normal block at 0x00D4C3E0, 44 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD E0 C3 D4 00
{841} normal block at 0x00D4BE60, 44 bytes long.
 Data: <            `   > CD CD CD CD CD CD CD CD CD CD CD CD 60 BE D4 00
{838} normal block at 0x00D4C2D8, 44 bytes long.
 Data: <                > CD CD CD CD D8 C2 D4 00 CA 1D 0E 84 8C CA C5 BF
{835} normal block at 0x00D4BE08, 44 bytes long.
 Data: <        y  ?q   > CD CD CD CD 08 BE D4 00 79 AD 9E 3F 71 19 D1 BF
{832} normal block at 0x00D4C178, 44 bytes long.
 Data: <    x    b  ^  ?> CD CD CD CD 78 C1 D4 00 D4 62 C7 FF 5E BC B4 3F
{829} normal block at 0x00D4C018, 44 bytes long.
 Data: <               ?> CD CD CD CD 18 C0 D4 00 B0 D2 AF D6 FF CB AE 3F
{826} normal block at 0x00D4C648, 44 bytes long.
 Data: <    H   Ua he%  > CD CD CD CD 48 C6 D4 00 55 61 05 68 65 25 C2 BF
{823} normal block at 0x00D4C228, 44 bytes long.
 Data: <    (   yY- 5   > CD CD CD CD 28 C2 D4 00 79 59 2D AC 35 E9 AF BF
{820} normal block at 0x00D4C6A0, 44 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD A0 C6 D4 00
{817} normal block at 0x00D4BF10, 44 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD 10 BF D4 00
{814} normal block at 0x00D4BF68, 44 bytes long.
 Data: <    h   Ua he%  > CD CD CD CD 68 BF D4 00 55 61 05 68 65 25 C2 BF
{811} normal block at 0x00D4C120, 44 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD 20 C1 D4 00
{808} normal block at 0x00D4C388, 44 bytes long.
 Data: <                > CD CD CD CD 88 C3 D4 00 CA 1D 0E 84 8C CA C5 BF
{805} normal block at 0x00D4C280, 44 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD 80 C2 D4 00
{802} normal block at 0x00D4C800, 44 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD 00 C8 D4 00
{799} normal block at 0x00D4C858, 44 bytes long.
 Data: <    X      *   ?> CD CD CD CD 58 C8 D4 00 A4 88 FF 2A 00 00 F0 3F
{796} normal block at 0x00D4C5F0, 44 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD F0 C5 D4 00
{793} normal block at 0x00D4BDB0, 44 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD B0 BD D4 00
{790} normal block at 0x00D4C0C8, 44 bytes long.
 Data: <                > CD CD CD CD C8 C0 D4 00 DD B5 0B 0F FD FF EF BF
{787} normal block at 0x00D4BFC0, 44 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD C0 BF D4 00
{784} normal block at 0x00D4C330, 44 bytes long.
 Data: <            0   > CD CD CD CD CD CD CD CD CD CD CD CD 30 C3 D4 00
{781} normal block at 0x00D4C7A8, 44 bytes long.
 Data: <         u @J3 ?> CD CD CD CD A8 C7 D4 00 99 75 88 40 4A 33 CC 3F
{778} normal block at 0x00D4C070, 44 bytes long.
 Data: <            p   > CD CD CD CD CD CD CD CD CD CD CD CD 70 C0 D4 00
{775} normal block at 0x00D4B6A8, 44 bytes long.
 Data: <        ?    i  > CD CD CD CD A8 B6 D4 00 3F 0E 93 08 10 69 B0 BF
{772} normal block at 0x00D4BAC8, 44 bytes long.
 Data: <         1m F  ?> CD CD CD CD C8 BA D4 00 15 31 6D EA 46 ED C4 3F
{769} normal block at 0x00D4BA70, 44 bytes long.
 Data: <            p   > CD CD CD CD CD CD CD CD CD CD CD CD 70 BA D4 00
{766} normal block at 0x00D4B9C0, 44 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD C0 B9 D4 00
{763} normal block at 0x00D4BB20, 44 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD 20 BB D4 00
{760} normal block at 0x00D4BC80, 44 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD 80 BC D4 00
{757} normal block at 0x00D4B758, 44 bytes long.
 Data: <    X    F 4O  ?> CD CD CD CD 58 B7 D4 00 AB 46 D5 34 4F 12 C0 3F
{754} normal block at 0x00D4B968, 44 bytes long.
 Data: <    h      M   ?> CD CD CD CD 68 B9 D4 00 E5 82 13 4D C8 0A AC 3F
{751} normal block at 0x00D4BCD8, 44 bytes long.
 Data: <         >L  " ?> CD CD CD CD D8 BC D4 00 10 3E 4C 0E 89 22 B6 3F
{748} normal block at 0x00D4B910, 44 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD 10 B9 D4 00
{745} normal block at 0x00D4B5A0, 44 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD A0 B5 D4 00
{742} normal block at 0x00D4B650, 44 bytes long.
 Data: <            P   > CD CD CD CD CD CD CD CD CD CD CD CD 50 B6 D4 00
{739} normal block at 0x00D4BC28, 44 bytes long.
 Data: <    (    V     ?> CD CD CD CD 28 BC D4 00 AD 56 FC 05 00 00 F0 3F
{736} normal block at 0x00D4B8B8, 44 bytes long.
 Data: <             I ?> CD CD CD CD B8 B8 D4 00 00 00 00 E0 DB 49 90 3F
{733} normal block at 0x00D4B860, 44 bytes long.
 Data: <            `   > CD CD CD CD CD CD CD CD CD CD CD CD 60 B8 D4 00
{730} normal block at 0x00D4BA18, 44 bytes long.
 Data: <        k 4     > CD CD CD CD 18 BA D4 00 6B 06 34 F3 FF FF EF BF
{727} normal block at 0x00D4B808, 44 bytes long.
 Data: <        } j    ?> CD CD CD CD 08 B8 D4 00 7D CB 6A E4 D3 AE D1 3F
{724} normal block at 0x00D4B7B0, 44 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD B0 B7 D4 00
{721} normal block at 0x00D4BBD0, 44 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD D0 BB D4 00
{718} normal block at 0x00D4BB78, 44 bytes long.
 Data: <    x    M .   ?> CD CD CD CD 78 BB D4 00 E0 4D D0 2E 92 D6 A2 3F
{715} normal block at 0x00D4B700, 44 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD 00 B7 D4 00
{712} normal block at 0x00D4B520, 44 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD 20 B5 D4 00
{709} normal block at 0x00D4B4C8, 44 bytes long.
 Data: <         w2    ?> CD CD CD CD C8 B4 D4 00 BD 77 32 01 00 00 F0 3F
{706} normal block at 0x00D4B470, 44 bytes long.
 Data: <            p   > CD CD CD CD CD CD CD CD CD CD CD CD 70 B4 D4 00
{703} normal block at 0x00D4B418, 44 bytes long.
 Data: <        @     q > CD CD CD CD 18 B4 D4 00 40 9A 99 19 90 E3 71 BF
{700} normal block at 0x00D4B3C0, 44 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD C0 B3 D4 00
{697} normal block at 0x00D4B368, 44 bytes long.
 Data: <    h   $33{ C ?> CD CD CD CD 68 B3 D4 00 24 33 33 7B F4 43 B3 3F
{694} normal block at 0x00D4B310, 44 bytes long.
 Data: <                > CD CD CD CD CD CD CD CD CD CD CD CD 10 B3 D4 00
{691} normal block at 0x00D4B2B8, 44 bytes long.
 Data: <           _X  ?> CD CD CD CD B8 B2 D4 00 D0 FF FF 5F 58 8B 95 3F
{686} normal block at 0x00D2B148, 44 bytes long.
 Data: <    H    fff V~?> CD CD CD CD 48 B1 D2 00 C0 66 66 66 F0 56 7E 3F
{671} normal block at 0x00D197C0, 8 bytes long.
 Data: < z   u O> EF 7A FE C5 96 75 E0 4F
Object dump complete.

这是OpenCV的错误还是我对图书馆的错误使用? 如何避免这种泄漏?

0 个答案:

没有答案