diff options
| author | Leo Chan <leochanj@live.unc.edu> | 2020-10-22 01:53:21 -0400 |
|---|---|---|
| committer | Joshua Bakita <jbakita@cs.unc.edu> | 2020-10-22 01:56:35 -0400 |
| commit | d17b33131c14864bd1eae275f49a3f148e21cf29 (patch) | |
| tree | 0d8f77922e8d193cb0f6edab83018f057aad64a0 /SD-VBS/common/toolbox/lagrcv/lk_flow.cc | |
| parent | 601ed25a4c5b66cb75315832c15613a727db2c26 (diff) | |
Squashed commit of the sb-vbs branch.
Includes the SD-VBS benchmarks modified to:
- Use libextra to loop as realtime jobs
- Preallocate memory before starting their main computation
- Accept input via stdin instead of via argc
Does not include the SD-VBS matlab code.
Fixes libextra execution in LITMUS^RT.
Diffstat (limited to 'SD-VBS/common/toolbox/lagrcv/lk_flow.cc')
| -rwxr-xr-x | SD-VBS/common/toolbox/lagrcv/lk_flow.cc | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/SD-VBS/common/toolbox/lagrcv/lk_flow.cc b/SD-VBS/common/toolbox/lagrcv/lk_flow.cc new file mode 100755 index 0000000..c083048 --- /dev/null +++ b/SD-VBS/common/toolbox/lagrcv/lk_flow.cc | |||
| @@ -0,0 +1,76 @@ | |||
| 1 | |||
| 2 | /* compile with | ||
| 3 | lk_flow.cc -I/usr/local/opencv/include -L/usr/local/opencv/lib -lcxcore -lcv | ||
| 4 | */ | ||
| 5 | |||
| 6 | #include "mex.h" | ||
| 7 | #include "opencv/cv.h" | ||
| 8 | #include "opencv/highgui.h" | ||
| 9 | #include <stdio.h> | ||
| 10 | #include <math.h> | ||
| 11 | |||
| 12 | void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { | ||
| 13 | // usage: [ velx vely ] = lk_flow(image1,image2,winsize) | ||
| 14 | // images must be single-channel, 8-bit | ||
| 15 | |||
| 16 | const int *backwards_imdims = mxGetDimensions(prhs[0]); | ||
| 17 | int imdims[2] = { backwards_imdims[1], backwards_imdims[0] }; | ||
| 18 | int winsize = (int)mxGetScalar(prhs[2]); | ||
| 19 | plhs[0] = mxCreateNumericArray(2, imdims, mxSINGLE_CLASS, mxREAL); | ||
| 20 | plhs[1] = mxCreateNumericArray(2, imdims, mxSINGLE_CLASS, mxREAL); | ||
| 21 | |||
| 22 | printf("imsize %d %d\n", imdims[0], imdims[1]); | ||
| 23 | |||
| 24 | IplImage *im1 = | ||
| 25 | cvCreateImageHeader(cvSize(imdims[0], imdims[1]), IPL_DEPTH_8U, 1); | ||
| 26 | IplImage *im2 = | ||
| 27 | cvCreateImageHeader(cvSize(imdims[0], imdims[1]), IPL_DEPTH_8U, 1); | ||
| 28 | IplImage *flow_x = | ||
| 29 | cvCreateImageHeader(cvSize(imdims[0], imdims[1]), IPL_DEPTH_32F, 1); | ||
| 30 | IplImage *flow_y = | ||
| 31 | cvCreateImageHeader(cvSize(imdims[0], imdims[1]), IPL_DEPTH_32F, 1); | ||
| 32 | |||
| 33 | im1->imageData = (char*)mxGetPr(prhs[0]); | ||
| 34 | im2->imageData = (char*)mxGetPr(prhs[1]); | ||
| 35 | flow_x->imageData = (char*)mxGetPr(plhs[0]); | ||
| 36 | flow_y->imageData = (char*)mxGetPr(plhs[1]); | ||
| 37 | |||
| 38 | cvCalcOpticalFlowLK(im1, im2, cvSize(winsize,winsize), flow_x, flow_y); | ||
| 39 | |||
| 40 | for (int row = 0; row < imdims[0]; row += 10) { | ||
| 41 | for (int col = 0; col < imdims[1]; col += 10) { | ||
| 42 | cvLine(im1, cvPoint(col,row), | ||
| 43 | cvPoint(int(col + flow_x->imageData[imdims[1] * row + col]), | ||
| 44 | int(row + flow_y->imageData[imdims[1] * row + col])), | ||
| 45 | CV_RGB(1,0,0), | ||
| 46 | 1, | ||
| 47 | CV_AA, | ||
| 48 | 0); | ||
| 49 | |||
| 50 | } | ||
| 51 | } | ||
| 52 | |||
| 53 | cvDestroyAllWindows(); | ||
| 54 | cvNamedWindow("imfoo",CV_WINDOW_AUTOSIZE); | ||
| 55 | // IplImage *myim = cvLoadImage("lena.jpg", -1); | ||
| 56 | cvShowImage("imfoo",im1); | ||
| 57 | // cvShowImage("imfoo",myim); | ||
| 58 | cvWaitKey(0); | ||
| 59 | |||
| 60 | // cvCircle(flow_x, cvPoint( 40, 20), 15, CV_RGB(10,100,100), 5); | ||
| 61 | |||
| 62 | /* | ||
| 63 | FILE* filefx = fopen("fx.pgm", "w"); | ||
| 64 | FILE* filefy = fopen("fy.pgm", "w"); | ||
| 65 | fprintf(filefx, "P5\n%d %d\n255\n", imdims[1], imdims[0]); | ||
| 66 | fprintf(filefy, "P5\n%d %d\n255\n", imdims[1], imdims[0]); | ||
| 67 | float *ptr = (float*)flow_x->imageData; | ||
| 68 | for (int i = 0; i < imdims[1] * imdims[0]; i++) { | ||
| 69 | // if (fabs(++ptr*) > 0.1) | ||
| 70 | if (fabs(*ptr++) > 0.1) fprintf(filefx, "1"); | ||
| 71 | else fprintf(filefx, "0"); | ||
| 72 | } | ||
| 73 | fclose(filefx); | ||
| 74 | fclose(filefy); | ||
| 75 | */ | ||
| 76 | } | ||
