/*******************************************************************************
* Copyright 2015-2018 Intel Corporation.
*
* This software and the related documents are Intel copyrighted materials, and
* your use of them is governed by the express license under which they were
* provided to you (License). Unless the License provides otherwise, you may not
* use, modify, copy, publish, distribute, disclose or transmit this software or
* the related documents without Intel's prior written permission.
*
* This software and the related documents are provided as is, with no express
* or implied warranties, other than those that are expressly stated in the
* License.
*******************************************************************************/
// A simple example of computing Hu moment values for images.
// implemented with Intel(R) Integrated Primitives (Intel(R) IPP) functions:
// ippiSet_8u_C1R
// ippiMomentGetStateSize_64f
// ippiMomentInit_64f
// ippiMoments64f_8u_C1R
// ippiGetHuMoments_64f
#include <stdio.h>
#include "ipp.h"
/* Next two defines are created to simplify code reading and understanding */
#define EXIT_MAIN exitLine: /* Label for Exit */
#define check_sts(st) if((st) != ippStsNoErr) goto exitLine; /* Go to Exit if Intel(R) IPP function returned status different from ippStsNoErr */
/* Results of ippMalloc() are not validated because Intel(R) IPP functions perform bad arguments check and will return an appropriate status */
int main(void)
{
IppStatus status = ippStsNoErr;
Ipp8u pSrc[64]; /* Pointer to source image */
IppiSize roiA={8,8}, roiH={8,1}, roiV={1,8}; /* Used image ROI sizes */
int sizeState = 0; /* State size */
IppiHuMoment_64f hmH = {0}, hmV= {0}; /* Horizontal and vertical moments */
IppiMomentState_64f *pState = NULL; /* Pointers to state structure */
check_sts( status = ippiMomentGetStateSize_64f(ippAlgHintNone, &sizeState) )
/* memory allocation */
pState = (IppiMomentState_64f*) ippMalloc( sizeState );
check_sts( status = ippiMomentInit_64f(pState, ippAlgHintNone) )
/* set horizontal edge */
check_sts( status = ippiSet_8u_C1R( 0, pSrc, 8, roiA ) )
check_sts( status = ippiSet_8u_C1R( 3, pSrc, 8, roiH ) )
/* compute spatial moment values */
check_sts( status = ippiMoments64f_8u_C1R( pSrc, 8, roiA, pState ) )
/* compute seven Hu moment invariants */
check_sts( status = ippiGetHuMoments_64f( pState, 0, hmH ) )
/* set vertical edge */
check_sts( status = ippiSet_8u_C1R( 0, pSrc, 8, roiA ) )
check_sts( status = ippiSet_8u_C1R( 3, pSrc, 8, roiV ) )
/* compute spatial moment values */
check_sts( status = ippiMoments64f_8u_C1R( pSrc, 8, roiA, pState ) )
/* compute seven Hu moment invariants */
check_sts( status = ippiGetHuMoments_64f( pState, 0, hmV ) )
EXIT_MAIN
ippFree( pState );
printf("Exit status %d (%s)\n", (int)status, ippGetStatusString(status));
return (int)status;
}