void alignment(std::vector<cv::Mat> images, std::vector<cv::Point>& out) { int num = images.size(); out.resize(num); cv::Mat gray1; cv::cvtColor(images[0], gray1, cv::COLOR_BGR2GRAY); out[0] = cv::Point(0, 0); for (int i = 1; i < num; ++i) { const cv::Mat& image1 = images[i-1]; const cv::Mat& image2 = images[i]; cv::Point& outOffset = out[i-1]; cv::Point offset(0, 0); cv::Mat gray2; cv::cvtColor(image2, gray2, cv::COLOR_BGR2GRAY); computeOffset(gray1, gray2, 0, offset); out[i] = offset; printf("offset[%d] = %d %d\n", i, offset.x, offset.y); gray1 = gray2; } }
int parse_mxFullEntry(int row, mxArray *mxData, mxArray *mxLabels, WORD *words) { int i; int cols,rows; int index; double *data; data = mxGetPr(mxData); cols = mxGetN(mxData); rows = mxGetM(mxData); /* here we assume that the mxData is full, not sparse, * and relying on that assumption, we assign the word number * to be the position within the full array */ for (i = 0; i < cols; i++) { index = computeOffset(rows, cols, row, i); (words[i]).wnum=(i+1); /* assign the word number */ (words[i]).weight=(CFLOAT)data[index]; } /* assign the last word to be 0 (null) to note the end of the list */ (words[i]).wnum = 0; return 0; }
double oclMorphFilter::runSubtractKernel( const oclImage2DHolder& sourceA, const oclImage2DHolder& sourceB, oclImage2DHolder& output) { cl_int err; err = kernelSubtract.setArg(0, sourceA.img); err = kernelSubtract.setArg(1, sourceB.img); err |= kernelSubtract.setArg(2, output.img); if(!oclContext::oclError("Error while setting kernel arguments", err)) return 0.0; cl::NDRange offset(computeOffset(0, 0)); cl::NDRange gridDim(computeGlobal(0, 0)); cl::Event evt; err = ctx->commandQueue().enqueueNDRangeKernel( kernelSubtract, offset, gridDim, ctx->workgroupSize(), nullptr, &evt); evt.wait(); oclContext::oclError("Error while executing kernel over ND range!", err); return oclContext::oclElapsedEvent(evt); }
double oclMorphFilter::runMorphologyKernel( cl::Kernel* kernel, const oclImage2DHolder& source, oclImage2DHolder& output) { cl_int err; err = kernel->setArg(0, source.img); err |= kernel->setArg(1, output.img); err |= kernel->setArg(2, structuringElement.buf); err |= kernel->setArg(3, structuringElement.size / static_cast<int>(sizeof(cl_int2))); if(!oclContext::oclError("Error while setting kernel arguments", err)) return 0.0; cl::NDRange offset(computeOffset(0, 0)); cl::NDRange gridDim(computeGlobal(0, 0)); cl::Event evt; err = ctx->commandQueue().enqueueNDRangeKernel( *kernel, offset, gridDim, ctx->workgroupSize(), nullptr, &evt); evt.wait(); oclContext::oclError("Error while executing kernel over ND range!", err); return oclContext::oclElapsedEvent(evt); }
SUMOTime MSCalibrator::MSCalibrator_FileTriggeredChild::execute(SUMOTime) throw(ProcessError) { if (myParent.childCheckEmit(this)) { buildAndScheduleFlowVehicle(); return (SUMOTime) computeOffset(myFlow); } return 1; }
const uint32 IImage::computeOffset( const vgm::Vec3i position ) const { assert( isValid(position) ); const uint32 offset = computeOffset( position[0], position[1], position[2] ); return offset; }
static void computeOffset(cv::Mat img1, cv::Mat img2, int d, cv::Point& _off) { cv::Point offset; cv::Size size1 = img1.size(), size2 = img2.size(); if ((size1.width > 2 && size1.height > 2) && (size2.width > 2 && size2.height > 2) && (d < 16)) { cv::Mat tmp1, tmp2; cv::resize(img1, tmp1, cv::Size(), 0.5f, 0.5f); cv::resize(img2, tmp2, cv::Size(), 0.5f, 0.5f); computeOffset(tmp1, tmp2, d+1, offset); offset.x *= 2, offset.y *= 2; } else { offset.x = 0, offset.y = 0; } cv::Point result; cv::Mat tb1, tb2, eb1, eb2; computeBitmaps(img1, tb1, eb1); computeBitmaps(img2, tb2, eb2); cv::Rect bound1(cv::Point(0,0), size1); cv::Rect bound2(cv::Point(0,0), size2); int min_err = (bound1 & bound2).area(); for (int dx = -1; dx <= 1; ++dx) { for (int dy = -1; dy <= 1; ++dy) { cv::Point displace = offset + cv::Point(dx,dy); cv::Rect frame = bound1 & (bound2 + displace); cv::Rect shift = bound2 & (bound1 - displace); // ROIs cv::Mat framed_tb1(tb1, frame); cv::Mat framed_eb1(eb1, frame); cv::Mat shifted_tb2(tb2, shift); cv::Mat shifted_eb2(eb2, shift); // cv::Mat tmp1, tmp2; cv::bitwise_xor(framed_tb1, shifted_tb2, tmp1); cv::bitwise_and(tmp1, framed_eb1, tmp2); cv::bitwise_and(shifted_eb2, tmp2, tmp1); // int err = (int)cv::sum(tmp1)[0]; if (dx == 0 && dy == 0) err -= 1; if (err < min_err) { result = displace; min_err = err; } } } _off = result; }
void storeDocsFull(mxArray *mxStruct, char *name, DOC **docs, int ndocs, int nwords) { mxArray *fieldValue; double *tmpArray; int i,j; SVECTOR *fvec; WORD *words; DOC *doc; if (docs == NULL) return; fieldValue = mxCreateDoubleMatrix(ndocs, nwords, mxREAL); tmpArray = mxGetPr(fieldValue); /* zero out tmparray */ for (i = 0; i < (ndocs*nwords); i++) tmpArray[i] = 0; for (i = 0; i < ndocs; i++) { doc = docs[i]; if (doc == NULL) continue; fvec = doc->fvec; if (fvec == NULL) continue; words = fvec->words; if (words == NULL) continue; for (j = 0; words[j].wnum != 0; j++) { WORD w = words[j]; int index = computeOffset(ndocs, nwords, i,(w.wnum-1)); tmpArray[index] = w.weight; } } mxSetField(mxStruct,0, name, fieldValue); }
//****************** //Functions //****************** int main(int argc, char** argv){ //Convert the argv value into an integer unsigned int address = strtol(argv[1],NULL,10); //print a message repeating the address printf("The address %u contains:\n", address); if(DEBUG == 1){ perror(NULL); } //Print the message containing the page number printf("Page Number = %u\n", computePage(address)); if(DEBUG == 1){ perror(NULL); } //Print the messsage containing the offset printf("Offset = %u\n",computeOffset(address)); if(DEBUG == 1){ perror(NULL); } exit(0); }
/* call as model = mexsvmlearn(data,labels,options) */ void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) { int rows, cols,i,j,offset; double *kern,k; DOC **docs; SVECTOR *a, *b; MODEL *model; global_init(); /* load model parameters from the "model" parameter */ model = restore_model((mxArray *)prhs[1]); rows = mxGetM(prhs[0]); cols = mxGetN(prhs[0]); /* load the testing arrays into docs */ mexToDOC((mxArray *)prhs[0], NULL, &docs, NULL, NULL, NULL); /* setup output environment */ plhs[0] = mxCreateDoubleMatrix(rows,rows,mxREAL); kern = mxGetPr(plhs[0]); for (i = 0; i < rows; i++) { a = docs[i]->fvec; for (j = 0; j < rows; j++) { b = docs[j]->fvec; k = single_kernel(&(model->kernel_parm), a, b); offset = computeOffset(rows, rows, i, j); kern[offset] = k; } } global_destroy(); }
size_t PVField::getNumberFields() const { if(nextFieldOffset==0) computeOffset(this); return (nextFieldOffset - fieldOffset); }
size_t PVField::getNextFieldOffset() const { if(nextFieldOffset==0) computeOffset(this); return nextFieldOffset; }
void dxJointSlider::setRelativeValues() { computeOffset(); computeInitialRelativeRotation(); }