OpenCV and AfterEffects
Hello,
I am looking for some guidance for integrating OpenCV with the AE SDK.
Notes:
- I've read through most of the (excellent) documentation and successfully experimented with all of the sample projects.
- I've successfully built AE SDK linked with OpenCV4.1 dll's and can import and instantiate the basic OpenCV building blocks (eg. cv::Mat).
- I assume some of the native AE functionality uses OpenCV since I can see some opencv dll's in the AE binary folder. Also, plug-ins like 3D Camera Tracker likely use feature detection and tracking from OpenCV.
Where I'm stuck is copying input data to a cv::Mat object so that I can leverage the OpenCV library for computer vision.
After trying for a few days I'm quite stuck with memory allocation errors etc. and it is quite clear from the AE SDK docs that allocating your own memory without using the AE SDK macros is a recipe for disaster (fair enough).
I'm wondering if there is any hope for trying to accomplish the following (copied from the Render() function of the AE SDK Skeleton example):
static PF_Err
Render (
PF_InData *in_data,
PF_OutData *out_data,
PF_ParamDef *params[],
PF_LayerDef *output )
{
PF_Err err = PF_Err_NONE;
AEGP_SuiteHandler suites(in_data->pica_basicP);
// get input frame pixels from in_data
PF_EffectWorld *inputP = ¶ms[0]->u.ld;
// initialize 4-channel 8-bit Mat
cv::Mat mat = cv::Mat((int)output->height, (int)output->width, CV_8UC4);
// copy pixels to opencv mat
err = copyInput(&mat, inputP);
// do some computer vision stuff
err = doAwesomeComputerVision(&mat);
// copy opencv mat to output
err = copyToOutput(&mat, output);
return err;
}
Any guidance is greatly appreciated.
Thank you!
