以前別のプログラムで動画の読み込みができましたが、今現在取り組んでいるプログラムではうまくいきません。
言語はC++でopencv2.4.9を使用しています。
Os windows8.1 visual studio2013を使っています。
よろしくお願いします。
エラーメッセージ
OpenCV Error: Assertion failed (udata < (uchar*)ptr && ((uchar*)ptr - udata) <= (ptrdiff_t)(sizeof(void*)+16)) in cv::fastFree, file C:\builds\2_4_PackSlave-win32-vc12-shared\opencv\modules\core\src\alloc.cpp, line 78
void
1{ 2 if(ptr) 3 { 4 uchar* udata = ((uchar**)ptr)[-1]; 5 CV_DbgAssert(udata < (uchar*)ptr && 6 ((uchar*)ptr - udata) <= (ptrdiff_t)(sizeof(void*)+CV_MALLOC_ALIGN)); 7 free(udata); 8 } 9} 10コード
#include <opencv2/opencv.hpp> //静的リンクライブラリの指定 #include <opencv2/opencv_lib.hpp> #include "Classifier.h" #include "IntegralHistogram.h" #include "MeanShift.h" #include "Common.h" //画像を扱う構造体の宣言 IplImage* imgSource = NULL; //原画像 IplImage* imgResult = NULL; //人検出結果 IplImage* imgGray = NULL; //グレイスケール画像 //クラス CClassifier ob_CL; //Real AdaBoostによる識別 CIntegralHistogram ob_IH; //Integral HistogramによるHOG特徴量算出 CMeanShift ob_MS; //MeanShiftによる検出ウィンドウの統合 int main(){ int i, j, l; int frame = 0; CvCapture *capture = NULL; // カメラキャプチャ用の構造体 //出力ウィンドウの作成 char* winOriginal = "OutputImage"; cvNamedWindow(winOriginal, CV_WINDOW_AUTOSIZE); //検出ウィンドウのパラメータ int window_width = INIT_WINDOW_X; int window_height = INIT_WINDOW_Y; int window_count = 0; int window_ture_count = 0; int tcount = 0; double scale; //HOG特徴量の配列 double feature[FEATURE]; // 動画ファイルを開く if ((capture = cvCaptureFromFile("C:\\opencv\\sources\\samples\\c\\tree.avi")) == NULL) { // ファイルが見つからなかった場合 printf("ファイルが見つかりません\n"); exit(1); } imgSource = cvQueryFrame(capture); //領域確保 imgGray = cvCreateImage(cvGetSize(imgSource), IPL_DEPTH_8U, 1); //aviファイル設定 double fps = 25.0; CvVideoWriter* VideoWriter = cvCreateVideoWriter("C:\\opencv\\sources\\samples\\c\\result.avi", -1, fps, cvGetSize(imgSource), 1); //カラー画像からグレイスケール画像へ変換 cvCvtColor(imgSource, imgGray, CV_BGR2GRAY); //初期化 ob_IH.CreateGradLUT(); ob_CL.init(); ob_MS.Init(imgSource); ob_IH.Init(imgGray); cvReleaseImage(&imgSource); //人検出開始 while (1){ //画像の読み込み imgSource = cvQueryFrame(capture); if (imgSource == NULL) exit(1); printf("frame -> %d\n", frame); //積分画像の初期化 ob_IH.ClearIH(); // 画像サイズを保存 CvSize imageSize = cvGetSize(imgSource); //領域確保 imgResult = cvCreateImage(imageSize, IPL_DEPTH_8U, 3); //カラー画像からグレイスケール画像へ変換 cvCvtColor(imgSource, imgGray, CV_BGR2GRAY); //勾配方向と勾配強度,積分画像の算出 ob_IH.CreateIntegralHistogram(imgGray); //原画像のコピー memcpy(imgResult->imageData, imgSource->imageData, imgSource->width * imgSource->height * 3); //パラメータの初期化 window_width = INIT_WINDOW_X; window_height = INIT_WINDOW_Y; window_count = 0; window_ture_count = 0; //検出ウィンドウのスケール変化 for (scale = MIN_SCALE; scale < MAX_SCALE; scale += STEP_SCALE){ window_width = INIT_WINDOW_X * scale; window_height = INIT_WINDOW_Y * scale; //検出ウィンドウのラスタスキャン for (j = 0; j<imgSource->height - window_height; j += STEP_WIDTH){ for (i = 0; i<imgSource->width - window_width; i += STEP_WIDTH){ //特徴量抽出 ob_IH.Getfeature(feature, i, j, window_width, window_height); //検出ウィンドウが人であるかの識別 if (ob_CL.classifier(feature) == TRUE){ //検出ウィンドウの座標をストック ob_MS.Voting(i + (int)(window_width * 0.5), j + (int)(window_height * 0.5), window_ture_count, scale); window_ture_count++; } } } } //MeanShiftによる検出ウィンドウの統合 ob_MS.MeanShift(); //Nearest Neighborによる検出ウィンドウの統合 tcount = ob_MS.NearestNeighbor(); //人がいると識別された領域を矩形で囲む for (l = 0; l < tcount; l++){ //検出ウィンドウが統合された数がしきい値以下ならば人以外として判別 if (ob_MS.win[l].count >= TH_HEAD_COUNT){ //検出ウィンドウの縦幅と横幅を計算 window_width = INIT_WINDOW_X * ob_MS.win[l].new_scale; window_height = INIT_WINDOW_Y * ob_MS.win[l].new_scale; //検出ウィンドウを矩形で囲む cvRectangle(imgResult, cvPoint(ob_MS.win[l].new_x - window_width * 0.5, ob_MS.win[l].new_y - window_height * 0.5), cvPoint(ob_MS.win[l].new_x + window_width * 0.5, ob_MS.win[l].new_y + window_height * 0.5), CV_RGB(0, 0, 255), 2, 8, 0); } } //人検出結果を保存と出力 cvShowImage(winOriginal, imgResult); cvWaitKey(10); //1画面分の取り込み cvWriteFrame(VideoWriter, imgResult); // 確保したメモリを開放 cvReleaseImage(&imgSource); cvReleaseImage(&imgResult); frame++; } // 確保したメモリを開放 cvReleaseImage(&imgGray); cvReleaseVideoWriter(&VideoWriter); cvReleaseCapture(&capture); return 0; } コード