Example #1
0
struct IplImage *framescompare(struct IplImage *curr, struct IplImage *prev)
{
	int x, y, h, w;
	struct IplImage *res;
	unsigned char *pvdata, *cvdata;
	struct rct rectangle;

	h = curr->height;
	w = curr->width;
	
	cvdata = getvals(curr);

	pvdata = getvals(prev);
	
	res = ipl_cloneimg(prev);
	
	for(y = 0; y < h; y++) {
		for(x = 0; x < w; x++) {
			if(abs(cvdata[y * w + x] - pvdata[y * w + x]) > 20) {
				rectangle.x1 = x;
				rectangle.y1 = y;
				rectangle.x2 = x;
				rectangle.y2 = y;
				getobj(cvdata, pvdata, x, y, w, h, &rectangle);
			}
			if((rectangle.x2 - rectangle.x1) * (rectangle.y2 - rectangle.y1) > 50) {
			drawRectangle(res, rectangle.x1, rectangle.y1, rectangle.x2, rectangle.y2);
			}
		}
	}
	
	free(pvdata);
	free(cvdata);
	return res;
}
Example #2
0
File: cs_supp.c Project: nasa/QuIP
static void evaluate_error_c(void)
{
	double	err;
	double	x[MAX_OPT_PARAMS];
	int i;
	List *lp;
	Node *np;
#ifdef THREAD_SAFE_QUERY
	Query_Stack *qsp;
    
	assert(cs_qsp != NULL );
	qsp = cs_qsp;
#endif // THREAD_SAFE_QUERY


	getvals(x,n_prms);		/* get the parameter estimates */

	lp=opt_param_list();
	np=QLIST_HEAD(lp);
	i=0;
	while(np!=NULL && i < n_prms ){
		Opt_Param *opp;

		opp = (Opt_Param *)(np->n_data);
		opp->ans = (float) x[i];
		i++;
		np=np->n_next;
	}

	err=(*stept_user_func)(SINGLE_QSP_ARG);

	setfobj(err);
}
Example #3
0
int eyeget(IplImage *frame, int thres, CvPoint *center)
{
	unsigned char *vdata, *mask;
	int x, y, w, h, ax, ay, n, chans;
	int xmax, xmin, ymax, ymin;
	int r;

	chans = frame->nChannels;
	vdata = getvals(frame);
	h = frame->height;
	w = frame->width;
	mask = calloc(w * h, sizeof(char));

	ymax = 0;
	ymin = h;
	xmax = 0;
	xmin = w;

	n = 0;
	ax = 0;
	ax = ay = 0;
	r = -1;
	for (y = 0; y < h; y++) {
		for (x = 0; x < w; x++) {
			if (vdata[y * w + x] < thres) {
				frame->imageData[chans*(y*w+x)+0] = 255;
				frame->imageData[chans*(y*w+x)+1] = 0;
				frame->imageData[chans*(y*w+x)+2] = 0;
				n++;
				ax += x;
				ay += y;
				xmax = (x > xmax)? x : xmax;
				ymax = (y > ymax)? y : ymax;
				xmin = (x < xmin)? x : xmin;
				ymin = (y < ymin)? y : ymin;

			}
		}
	}

	if (n > 0) {	
		center->x = ax / n;
		center->y = ay / n;
		r = (xmax - xmin < ymax - ymin)? (xmax - xmin) / 2 : (ymax - ymin) / 2;
	}

	return r;
}
Example #4
0
struct IplImage *hornschunk(struct IplImage *curr, struct IplImage *prev, double alpha, int n, double *s)
{
	int x, y, w, h, i;
	double ix, iy, it; 
	double *un1, *vn1, aun, avn, *un, *vn;
	double len;
	struct IplImage *res;
	unsigned char *pvdata, *cvdata;
	
	h = curr->height;
	w = curr->width;

	cvdata = getvals(curr);

	pvdata = getvals(prev);
	
	res = ipl_cloneimg(prev);
	
		
	un1 = calloc(curr->width * curr->height, sizeof(double));
	vn1 = calloc(curr->width * curr->height, sizeof(double));
	for (i = 0; i < n; i++) {
		un = calloc(curr->width * curr->height, sizeof(double));
		vn = calloc(curr->width * curr->height, sizeof(double));

		for (y = 1; y < h - 1; y++) {
			for (x = 1; x < w - 1; x++) {
				ix = (double)(1 / 4.0 * (pvdata[(y+1)*w+x] - pvdata[y*w+x] + pvdata[(y+1)*w+(x+1)] - pvdata[y*w+(x+1)] 
						+ cvdata[(y+1)*w+x] - cvdata[y*w+x] + cvdata[(y+1)*w+(x+1)]-cvdata[y*w+(x+1)]));
				iy = (double)(1 / 4.0 * (pvdata[y*w+(x+1)] - pvdata[y*w+x] + pvdata[(y+1)*w+(x+1)] - pvdata[(y+1)*w+x] 
						+ cvdata[y*w+(x+1)] - cvdata[y*w+x] + cvdata[(y+1)*w+(x+1)]-cvdata[y*w+x]));
				it = (double)(1 / 4.0 * (cvdata[y*w+(x+1)] - pvdata[y*w+x] + cvdata[y*w+(x+1)] - pvdata[y*w+(x+1)] 
						+ cvdata[(y+1)*w+x] - pvdata[(y+1)*w+x] + cvdata[(y+1)*w+(x+1)]-cvdata[(y+1)*w+(x+1)]));
			
				aun = 1 / 6.0 * (double)(un[(y-1)*w+x] + un[(y+1)*w+x] + un[y*w+(x-1)] + un[y*w+(x+1)]) + 
						1/12.0 * (double)(un[(y-1)*w+(x-1)] + un[(y+1)*w+(x-1)] + un[(y+1)*w+(x-1)] + un[(y+1)*w+(x+1)]);
				avn = 1 / 6.0 * (double)(vn[(y-1)*w+x] + vn[(y+1)*w+x] + vn[y*w+(x-1)] + vn[y*w+(x+1)]) 
						+ 1/12.0 * (double)(vn[(y-1)*w+(x-1)] + vn[(y+1)*w+(x-1)] + vn[(y+1)*w+(x-1)] + vn[(y+1)*w+(x+1)]);

				un1[y * w + x] = aun - ix * (ix * aun + iy * avn + it) / (ix * ix + iy * iy + alpha * alpha);
				vn1[y * w + x] = avn - iy * (ix * aun + iy * avn + it) / (ix * ix + iy * iy + alpha * alpha);	  
			}
		}
		free(un);
		free(vn);

		un = un1;
		vn = vn1;
	}

	double maxlen = 0.0;
		
	for (y = 1; y < h - 1; y++) {
		for (x = 1; x < w - 1; x++) {
			len = sqrt(fabs(un1[y * w + x]) * fabs(un1[y * w + x]) + fabs(vn1[y * w + x]) * fabs(vn1[y * w + x]));
			if (len > 3.0){
				drawLine(res, (int)x, (int)y, (int)(x + un1[y * w + x]), (int)(y + vn1[y * w + x]));
				if (len >= maxlen)
					maxlen = len;
			}	
		}
	}
	*s = maxlen;
	free(un1);
	free(vn1);
	free(pvdata);
	free(cvdata);
	return res;
}
Example #5
0
File: cs_supp.c Project: nasa/QuIP
static void cstepit_scr_funk(void)
{
	char str[128];
	float	err;
	Variable *vp;
	int i;
	List *lp;
	Node *np;
	double ans[MAX_OPT_PARAMS];
#ifdef THREAD_SAFE_QUERY
	Query_Stack *qsp;

	assert(cs_qsp != NULL );
	qsp = cs_qsp;
#endif // THREAD_SAFE_QUERY


	/* ooh, icky:  getvals fetches global vars from cstepit module... */

	getvals(ans,n_prms);

	if( opt_func_string==NULL ){
		warn("No optimization string defined");
		return;
	}

	lp=_opt_param_list(SGL_DEFAULT_QSP_ARG);
	if( lp == NULL ){
		warn("No optimization parameters to vary!?");
		err=0.0;
		setfobj((double)err);
		return;
	}
	np=QLIST_HEAD(lp);

	/* stepit has passed us params in the ans array -
	 * we want to get them into named variables...
	 */
	i=0;
	while(np!=NULL && i < n_prms ){
		Opt_Param *opp;

		opp = (Opt_Param *)( np->n_data);
		sprintf(str,"%g",ans[i]);	/* why add 1?  fortan? */
		_assign_var(DEFAULT_QSP_ARG  opp->op_name,str);
		i++;
		np=np->n_next;
	}

	/* We used to call pushtext here, but we like digest
	 * because it automatically pushes and pops the top menu.
	 *
	 * chew_text doesn't work, however, because it doesn't block
	 * the interpreter, which returns to the terminal...
	 *
	 * We have a problem - calling optimization from another callback
	 * function causes it to exit when done!?
	 * It turns out that that was because older scripts (written
	 * for the old version that didn't push the top menu automatically)
	 * didn't have a quit after the call to optimize - ???
	 */

	digest(opt_func_string, OPTIMIZER_FILENAME);
	
	vp=var__of("error");
	if( vp == NULL ) {
		warn(ERROR_STRING);
		sprintf(ERROR_STRING,
	"variable \"error\" not set by script fragment \"%s\"!?",
			opt_func_string);
		err=0.0;
	} else sscanf(VAR_VALUE(vp),"%g",&err);

	setfobj((double)err);
}