github にあったプログラムを勉強のため動かそうとしているのですが、コンパイル時に
以下のようなエラーが出ます。エラーの意味は分かるのですが、文法上は問題ないように思い、
原因がわかりません。
もしかして初歩的なことかもわかりませんが、原因と修正方法についてご教示お願いいたします。
opencvについてはバージョン3.10、vc++12(windows10)で他のプログラムが動作することは確認できています。
エラー内容
#define GET_2D(mat, x, y, step) (mat[((step) * (y)) + (x)])
GET_2D使用部分で
1>levelset_method.cpp(190): error C3861: 'GET_2D': 識別子が見つかりませんでした
のエラーが出る。
c++
1コード#include <stdio.h> 2#include <string.h> 3#include <stdlib.h> 4#include <opencv/cv.h> 5#include <opencv/highgui.h> 6//#include <cv.h> 7//#include <highgui.h> 8 9#define WINDOW_NAME_1 "Window1" 10#define WINDOW_NAME_2 "Window2" 11 12/** 2次元行列matの(x, y)要素を取得*/ 13#define GET_2D(mat, x, y, step) (mat[((step) * (y)) + (x)]) 14 15/** statusのラベル */ 16enum { FARAWAY, BAND, RESET_BAND, FRONT }; 17 18/** 点の配列 */ 19typedef struct PointArray { 20 /** 点 */ 21 CvPoint *points; 22 /** 点の最大数 */ 23 int max_size; 24 /** 現在のデータ数 */ 25 int count; 26} PointArray; 27 28 29/** レベルセット法で使う画像データの型 */ 30typedef struct LevelSetImageType { 31 /** 各ピクセルの輝度(8ビットグレイスケール) */ 32 unsigned char *image_gray; 33 /** 各ピクセルの状態 */ 34 unsigned char *status; 35 /** 各ピクセルの補助関数の値 */ 36 double *phi; 37 /** 各ピクセルの補助関数の変化量 */ 38 double *dphi; 39 /** 各ピクセルの成長速度 */ 40 double *f; 41 /** 画像の幅 */ 42 uint width; 43 /** 画像の高さ */ 44 uint height; 45} LevelSetImage; 46 47LevelSetImage* new_levelset_image(const IplImage *src) { 48 int size = src->width * src->height; 49 LevelSetImage *img = (LevelSetImage*)malloc(sizeof(LevelSetImage)); 50 img->width = src->width; 51 img->height = src->height; 52 53 img->image_gray = (unsigned char *)malloc(sizeof(unsigned char) * size); 54 img->status = (unsigned char *)malloc(sizeof(unsigned char) * size); 55 img->phi = (double *)malloc(sizeof(double) * size); 56 img->dphi = (double *)malloc(sizeof(double) * size); 57 img->f = (double *)malloc(sizeof(double) * size); 58 59 memcpy(img->image_gray, src->imageData, sizeof(unsigned char) * size); 60 61 return img; 62} 63 64void free_levelset_image(LevelSetImage* img) { 65 free(img->image_gray); 66 free(img->status); 67 free(img->phi); 68 free(img->dphi); 69 free(img->f); 70 71 free(img); 72} 73 74PointArray* new_point_array(int max_size) { 75 PointArray* p = (PointArray *)malloc(sizeof(PointArray)); 76 if (p == NULL) 77 return NULL; 78 79 p->points = (CvPoint *)malloc(sizeof(CvPoint) * max_size); 80 if (p->points == NULL) { 81 free(p); 82 return NULL; 83 } 84 85 p->max_size = max_size; 86 p->count = 0; 87 return p; 88} 89 90void free_point_array(PointArray *p) { 91 free(p->points); 92 free(p); 93} 94 95PointArray** init_circle_map(int band_width) { 96 int x, y, i, d; 97 int num_points = 7 * (band_width + 1); 98 99 PointArray **circle_maps = (PointArray **)malloc(sizeof(PointArray *) * (band_width + 1)); 100 if (circle_maps == NULL) 101 return NULL; 102 103 for (i = 0; i < band_width + 1; i++) { 104 if ((circle_maps[i] = new_point_array(num_points)) == NULL) { 105 while (i >= 0) 106 free_point_array(circle_maps[i--]); 107 return NULL; 108 } 109 } 110 111 for (y = -band_width; y <= band_width; y++) { 112 for (x = -band_width; x <= band_width; x++) { 113 d = (int)sqrt(x * x + y * y); 114 if (d <= band_width) { 115 i = circle_maps[d]->count; 116 circle_maps[d]->points[i].x = x; 117 circle_maps[d]->points[i].y = y; 118 circle_maps[d]->count++; 119 } 120 } 121 } 122 return circle_maps; 123} 124 125void free_circle_maps(PointArray** circle_maps, int band_width) { 126 int i; 127 for (i = 0; i < band_width + 1; i++) 128 free_point_array(circle_maps[i]); 129 free(circle_maps); 130} 131 132void init_front(PointArray* front, LevelSetImage* img, 133 int init_offset, int band_width) { 134 int x, y, i; 135 int width, height; 136 width = img->width; 137 height = img->height; 138 139 memset(img->status, FARAWAY, width * height); 140 141 // Frontグリッドを設定 142 i = 0; 143 for (x = init_offset; x < width - init_offset; x++) { 144 GET_2D(img->status, x, init_offset, width) = FRONT; 145 GET_2D(img->phi, x, init_offset, width) = 0.0; 146 front->points[i].x = x; 147 front->points[i].y = init_offset; 148 i++; 149 150 GET_2D(img->status, x, height - init_offset - 1, width) = FRONT; 151 GET_2D(img->phi, x, height - init_offset - 1, width) = 0.0; 152 front->points[i].x = x; 153 front->points[i].y = height - init_offset - 1; 154 i++; 155 } 156
回答3件
あなたの回答
tips
プレビュー