int motionDetection(MotionDetect* md, Transform* trans, unsigned char *frame) { assert(md->initialized==2); md->currorig = frame; // smoothen image to do better motion detection // (larger stepsize or eventually gradient descent (need higher resolution) if (isRGB(md->fi.pFormat)) { // we could calculate a grayscale version and use the YUV stuff afterwards // so far only YUV implemented memcpy(md->curr, frame, md->fi.framesize); } else { // box-kernel smoothing (plain average of pixels), which is fine for us boxblurYUV(md->curr, frame, md->currtmp, &md->fi, md->stepSize*1/*1.4*/, BoxBlurNoColor); // two times yields tent-kernel smoothing, which may be better, but I don't // think we need it //boxblurYUV(md->curr, md->curr, md->currtmp, &md->fi, md->stepSize*1, // BoxBlurNoColor); } if (md->hasSeenOneFrame) { // md->curr = frame; if (isRGB(md->fi.pFormat)) { if (md->algo == 0) *trans = calcShiftRGBSimple(md); else if (md->algo == 1) *trans = calcTransFields(md, calcFieldTransRGB, contrastSubImgRGB); } else if (md->fi.pFormat == PF_YUV) { if (md->algo == 0) *trans = calcShiftYUVSimple(md); else if (md->algo == 1) *trans = calcTransFields(md, calcFieldTransYUV, contrastSubImgYUV); } else { ds_log_warn(md->modName, "unsupported Pixel Format (Codec: %i)\n", md->fi.pFormat); return DS_ERROR; } } else { md->hasSeenOneFrame = 1; *trans = null_transform(); } // copy current frame (smoothed) to prev for next frame comparison memcpy(md->prev, md->curr, md->fi.framesize); md->frameNum++; return DS_OK; }
int vsMotionDetection(VSMotionDetect* md, LocalMotions* motions, VSFrame *frame) { assert(md->initialized==2); md->currorig = *frame; // smoothen image to do better motion detection // (larger stepsize or eventually gradient descent (need higher resolution)) if (md->fi.pFormat > PF_PACKED) { // we could calculate a grayscale version and use the PLANAR stuff afterwards // so far smoothing is only implemented for PLANAR vsFrameCopy(&md->curr, frame, &md->fi); } else { // box-kernel smoothing (plain average of pixels), which is fine for us boxblurPlanar(&md->curr, frame, &md->currtmp, &md->fi, md->conf.stepSize*1/*1.4*/, BoxBlurNoColor); // two times yields tent-kernel smoothing, which may be better, but I don't // think we need it //boxblurPlanar(md->curr, md->curr, md->currtmp, &md->fi, md->stepSize*1, // BoxBlurNoColor); } if (md->hasSeenOneFrame) { LocalMotions motionscoarse; LocalMotions motionsfine; vs_vector_init(&motionsfine,0); // md->curr = frame; if (md->fi.pFormat > PF_PACKED) { motionscoarse = calcTransFields(md, &md->fieldscoarse, calcFieldTransPacked, contrastSubImgPacked); } else { // PLANAR motionscoarse = calcTransFields(md, &md->fieldscoarse, calcFieldTransPlanar, contrastSubImgPlanar); } int num_motions = vs_vector_size(&motionscoarse); if (num_motions < 1) { vs_log_warn(md->conf.modName, "too low contrast. \ (no translations are detected in frame %i)\n", md->frameNum); }else{