[Gridflow-cvs] [svn] commit: r3999 - /trunk/optional/opencv.c

gridflow-cvs at artengine.ca gridflow-cvs at artengine.ca
Thu Jul 10 10:56:41 EDT 2008


Author: matju
Date: Thu Jul 10 10:56:40 2008
New Revision: 3999

Log:
added atom converters for CvPoint,CvSize,CvScalar

Modified:
    trunk/optional/opencv.c

Modified: trunk/optional/opencv.c
==============================================================================
--- trunk/optional/opencv.c (original)
+++ trunk/optional/opencv.c Thu Jul 10 10:56:40 2008
@@ -122,6 +122,54 @@
 	return a;
 }
 
+void cvMatSend(const CvMat *self, FObject *obj, int outno) {
+	int m = self->rows;
+	int n = self->cols;
+	int e = CV_MAT_TYPE(cvGetElemType(self));
+	int c = CV_MAT_CN(  cvGetElemType(self));
+	GridOutlet *out = new GridOutlet(obj,0,new Dim(m,n));
+	for (int i=0; i<m; i++) {
+		uchar *meuh = cvPtr2D(self,i,0,0);
+		switch (e) {
+		  case CV_8U:  out->send(c*n,  (uint8 *)meuh); break;
+		  case CV_16S: out->send(c*n,  (int16 *)meuh); break;
+		  case CV_32S: out->send(c*n,  (int32 *)meuh); break;
+		  case CV_32F: out->send(c*n,(float32 *)meuh); break;
+		  case CV_64F: out->send(c*n,(float64 *)meuh); break;
+		}
+	}
+}
+
+#define binbuf_addv(SELF,FMT,ARGS...) binbuf_addv(SELF,const_cast<char *>(FMT),ARGS)
+
+void set_atom (t_atom *a, CvPoint &v) {
+	t_binbuf *b = binbuf_new();
+	binbuf_addv(b,"ii",v.y,v.x);
+	SETLIST(a,b);
+}
+void set_atom (t_atom *a, CvSize &v) {
+	t_binbuf *b = binbuf_new();
+	binbuf_addv(b,"ii",v.height,v.width);
+	SETLIST(a,b);
+}
+void set_atom (t_atom *a, CvScalar &scal) {
+	t_binbuf *b = binbuf_new();
+	binbuf_addv(b,"ffff",scal.val[0],scal.val[1],scal.val[2],scal.val[3]);
+	SETLIST(a,b);
+}
+#define USELIST \
+	if (a.a_type != A_LIST) RAISE("expected listatom"); \
+	t_list *b = (t_list *)a.a_gpointer; \
+	int argc = binbuf_getnatom(b); \
+	t_atom *argv = binbuf_getvec(b);
+#define GETF(I)     atom_getfloatarg(I,argc,argv)
+#define GETI(I) int(atom_getfloatarg(I,argc,argv))
+CvPoint  convert (const t_atom &a, CvPoint *)   {USELIST; return cvPoint( GETI(0),GETI(1));}
+CvSize   convert (const t_atom &a, CvSize *)    {USELIST; return cvSize(  GETI(0),GETI(1));}
+CvScalar convert (const t_atom &a, CvScalar *)  {USELIST; return cvScalar(GETF(0),GETF(1),GETF(2),GETF(3));}
+
+/* ******************************** CLASSES ******************************** */
+
 \class CvOp1 : FObject {
 	\attr CvMode mode;
 	\constructor () {mode = cv_mode_auto;}
@@ -224,116 +272,32 @@
 } GRID_END
 \end class {install("cv.SVD",1,3);}
 
-\class CvSplit : CvOp1 {
-	int channels;
-	\constructor (int channels) {
-		if (channels<0 || channels>64) RAISE("channels=%d is not in 1..64",channels);
-		this->channels = channels;
-		bself->noutlets_set(channels);
-	}
-};
-\end class {}
-
-\class CvHaarDetectObjects : FObject {
-	\attr double scale_factor; /*=1.1*/
-	\attr int min_neighbors;   /*=3*/
-	\attr int flags;           /*=0*/
+\class CvEllipse : FObject {
+	\grin 0
+	\attr CvPoint center;
+	\attr CvSize axes;
+	\attr double angle;
+	\attr double start_angle;
+	\attr double end_angle;
+	\attr CvScalar color;
+	\attr int thickness;
+	\attr int line_type;
+	\attr int shift;
 	\constructor () {
-		scale_factor=1.1;
-		min_neighbors=3;
-		flags=0;
-		//cascade = cvLoadHaarClassifierCascade("<default_face_cascade>",cvSize(24,24));
-		const char *filename = OPENCV_SHARE_PATH "/haarcascades/haarcascade_frontalface_alt2.xml";
-		FILE *f = fopen(filename,"r");
-		if (!f) RAISE("error opening %s: %s",filename,strerror(errno));
-		fclose(f);
-		cascade = (CvHaarClassifierCascade *)cvLoad(filename,0,0,0);
-		int s = cvGetErrStatus();
-		post("cascade=%p, cvGetErrStatus=%d cvErrorStr=%s",cascade,s,cvErrorStr(s));
-		//cascade = cvLoadHaarClassifierCascade(OPENCV_SHARE_PATH "/data/haarcascades/haarcascade_frontalface_alt2.xml",cvSize(24,24));
-		storage = cvCreateMemStorage(0);
-	}
-	CvHaarClassifierCascade *cascade;
-	CvMemStorage *storage;
-	\grin 0
-};
-GRID_INLET(CvHaarDetectObjects,0) {
+		center=cvPoint(0,0); axes=cvSize(0,0); angle=0; start_angle=0; end_angle=0; color=cvScalar(0);
+		thickness=1; line_type=8; shift=0;
+	}
+};
+GRID_INLET(CvEllipse,0) {
 	in->set_chunk(0);
 } GRID_FLOW {
 	PtrGrid l = new Grid(in->dim,(T *)data);
 	IplImage *img = cvImageGrid(l);
-	CvSeq *ret = cvHaarDetectObjects(img,cascade,storage,scale_factor,min_neighbors,flags);
-	int n = ret ? ret->total : 0;
-	out = new GridOutlet(this,0,new Dim(n,2,2));
-	for (int i=0; i<n; i++) {
-		CvRect *r = (CvRect *)cvGetSeqElem(ret,i);
-		int32 duh[] = {r->y,r->x,r->y+r->height,r->x+r->width};
-		out->send(4,duh);
-	}
-} GRID_END
-\end class {install("cv.HaarDetectObjects",2,1);}
-
-\class CvKalmanWrapper : CvOp1 {
-	CvKalman *kal;
-	\constructor (int dynam_params, int measure_params, int control_params=0) {
-		kal = cvCreateKalman(dynam_params,measure_params,control_params);
-	}
-	~CvKalmanWrapper () {if (kal) cvReleaseKalman(&kal);}
-	\decl void _0_bang ();
-	\grin 0
-	\grin 1
-};
-
-void cvMatSend(const CvMat *self, FObject *obj, int outno) {
-	int m = self->rows;
-	int n = self->cols;
-	int e = CV_MAT_TYPE(cvGetElemType(self));
-	int c = CV_MAT_CN(  cvGetElemType(self));
-	GridOutlet *out = new GridOutlet(obj,0,new Dim(m,n));
-	for (int i=0; i<m; i++) {
-		uchar *meuh = cvPtr2D(self,i,0,0);
-		switch (e) {
-		  case CV_8U:  out->send(c*n,  (uint8 *)meuh); break;
-		  case CV_16S: out->send(c*n,  (int16 *)meuh); break;
-		  case CV_32S: out->send(c*n,  (int32 *)meuh); break;
-		  case CV_32F: out->send(c*n,(float32 *)meuh); break;
-		  case CV_64F: out->send(c*n,(float64 *)meuh); break;
-		}
-	}
-}
-
-\def void _0_bang () {
-	const CvMat *r = cvKalmanPredict(kal,0);
-	cvMatSend(r,this,0);
-}
-
-GRID_INLET(CvKalmanWrapper,0) {
-	in->set_chunk(0);
-} GRID_FLOW {
-	PtrGrid l = new Grid(in->dim,(T *)data);
-	CvMat *a = (CvMat *)cvGrid(l,mode,2);
-	const CvMat *r = cvKalmanPredict(kal,a);
-	cvMatSend(r,this,0);
-} GRID_END
-
-GRID_INLET(CvKalmanWrapper,1) {
-	in->set_chunk(0);
-} GRID_FLOW {
-	PtrGrid l = new Grid(in->dim,(T *)data);
-	CvMat *a = (CvMat *)cvGrid(l,mode,2);
-	const CvMat* r = cvKalmanCorrect(kal,a);
-	cvMatSend(r,this,0);
-} GRID_END
-\end class {install("cv.Kalman",2,1);}
-
-//\class CvEllipse : FObject {
-//	\grin 0
-//};
-//GRID_INLET(CvEllipse,0) {
-//	in->set_chunk(0);
-//} GRID_FLOW {
-//} GRID_END
-//\end class {install("cv.Ellipse",1,1);}
+	cvEllipse(img,center,axes,angle,start_angle,end_angle,color,thickness,line_type,shift);
+	cvReleaseImageHeader(&img);
+	out = new GridOutlet(this,0,in->dim,in->nt); out->send(in->dim->prod(),data);
+} GRID_END
+\end class {install("cv.Ellipse",1,2);}
 
 /*
 void cvEllipse( CvArr* img, CvPoint center, CvSize axes, double angle,
@@ -363,6 +327,90 @@
 int  cvCamShift( const CvArr* prob_image, CvRect window, CvTermCriteria criteria, CvConnectedComp* comp, CvBox2D* box=NULL );
 */
 
+/* ******************************** UNFINISHED ******************************** */
+
+\class CvSplit : CvOp1 {
+	int channels;
+	\constructor (int channels) {
+		if (channels<0 || channels>64) RAISE("channels=%d is not in 1..64",channels);
+		this->channels = channels;
+		bself->noutlets_set(channels);
+	}
+};
+\end class {}
+
+\class CvHaarDetectObjects : FObject {
+	\attr double scale_factor; /*=1.1*/
+	\attr int min_neighbors;   /*=3*/
+	\attr int flags;           /*=0*/
+	\constructor () {
+		scale_factor=1.1;
+		min_neighbors=3;
+		flags=0;
+		//cascade = cvLoadHaarClassifierCascade("<default_face_cascade>",cvSize(24,24));
+		const char *filename = OPENCV_SHARE_PATH "/haarcascades/haarcascade_frontalface_alt2.xml";
+		FILE *f = fopen(filename,"r");
+		if (!f) RAISE("error opening %s: %s",filename,strerror(errno));
+		fclose(f);
+		cascade = (CvHaarClassifierCascade *)cvLoad(filename,0,0,0);
+		int s = cvGetErrStatus();
+		post("cascade=%p, cvGetErrStatus=%d cvErrorStr=%s",cascade,s,cvErrorStr(s));
+		//cascade = cvLoadHaarClassifierCascade(OPENCV_SHARE_PATH "/data/haarcascades/haarcascade_frontalface_alt2.xml",cvSize(24,24));
+		storage = cvCreateMemStorage(0);
+	}
+	CvHaarClassifierCascade *cascade;
+	CvMemStorage *storage;
+	\grin 0
+};
+GRID_INLET(CvHaarDetectObjects,0) {
+	in->set_chunk(0);
+} GRID_FLOW {
+	PtrGrid l = new Grid(in->dim,(T *)data);
+	IplImage *img = cvImageGrid(l);
+	CvSeq *ret = cvHaarDetectObjects(img,cascade,storage,scale_factor,min_neighbors,flags);
+	int n = ret ? ret->total : 0;
+	out = new GridOutlet(this,0,new Dim(n,2,2));
+	for (int i=0; i<n; i++) {
+		CvRect *r = (CvRect *)cvGetSeqElem(ret,i);
+		int32 duh[] = {r->y,r->x,r->y+r->height,r->x+r->width};
+		out->send(4,duh);
+	}
+} GRID_END
+\end class {install("cv.HaarDetectObjects",2,1);}
+
+\class CvKalmanWrapper : CvOp1 {
+	CvKalman *kal;
+	\constructor (int dynam_params, int measure_params, int control_params=0) {
+		kal = cvCreateKalman(dynam_params,measure_params,control_params);
+	}
+	~CvKalmanWrapper () {if (kal) cvReleaseKalman(&kal);}
+	\decl void _0_bang ();
+	\grin 0
+	\grin 1
+};
+\def void _0_bang () {
+	const CvMat *r = cvKalmanPredict(kal,0);
+	cvMatSend(r,this,0);
+}
+GRID_INLET(CvKalmanWrapper,0) {
+	in->set_chunk(0);
+} GRID_FLOW {
+	PtrGrid l = new Grid(in->dim,(T *)data);
+	CvMat *a = (CvMat *)cvGrid(l,mode,2);
+	const CvMat *r = cvKalmanPredict(kal,a);
+	cvMatSend(r,this,0);
+} GRID_END
+
+GRID_INLET(CvKalmanWrapper,1) {
+	in->set_chunk(0);
+} GRID_FLOW {
+	PtrGrid l = new Grid(in->dim,(T *)data);
+	CvMat *a = (CvMat *)cvGrid(l,mode,2);
+	const CvMat* r = cvKalmanCorrect(kal,a);
+	cvMatSend(r,this,0);
+} GRID_END
+\end class {install("cv.Kalman",2,1);}
+
 /* **************************************************************** */
 
 static int erreur_handleur (int status, const char* func_name, const char* err_msg, const char* file_name, int line, void *userdata) {



More information about the Gridflow-cvs mailing list