/*
// Copyright 2015 2016 Intel Corporation All Rights Reserved.
//
// The source code, information and material ("Material") contained herein is
// owned by Intel Corporation or its suppliers or licensors, and title
// to such Material remains with Intel Corporation or its suppliers or
// licensors. The Material contains proprietary information of Intel
// or its suppliers and licensors. The Material is protected by worldwide
// copyright laws and treaty provisions. No part of the Material may be used,
// copied, reproduced, modified, published, uploaded, posted, transmitted,
// distributed or disclosed in any way without Intel's prior express written
// permission. No license under any patent, copyright or other intellectual
// property rights in the Material is granted to or conferred upon you,
// either expressly, by implication, inducement, estoppel or otherwise.
// Any license under such intellectual property rights must be express and
// approved by Intel in writing.
//
// Unless otherwise agreed by Intel in writing,
// you may not remove or alter this notice or any other notice embedded in
// Materials by Intel or Intel's suppliers or licensors in any way.
*/
// A simple example of computing HOG descriptor using Intel IPP functions:
// ippiHOGGetSize
// ippiHOGInit
// ippiHOGGetBufferSize
// ippiHOGGetDescriptorSize
// ippiHOG_8u32f_C1R
#include <stdio.h>
#include "ipp.h"
#define WIND_WIDTH 64 /* detection window width */
#define WIND_HEIGHT 128 /* detection window image height */
/* 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 IPP function returned status different from ippStsNoErr */
/* Results of ippMalloc() are not validated because Intel(R) Integrated Performance Primitives functions perform bad arguments check and will return an appropriate status */
static IppiHOGConfig config = { /* HOG configure structure */
1, /* Use OpenCV compatible output format */
8, /* Cell size (pixels) */
16, /* Block size (pixels) */
8, /* Block stride size (pixels) */
9, /* Number of bins (orientations) in the histogram */
1.0f, /* Sigma value (in the applied Gaussian) */
0.2f, /* Threshold value (applied for normalization) */
{WIND_WIDTH, WIND_HEIGHT}, /* Size (width and height in pixels) of detection window */
};
int main(void)
{
IppStatus status = ippStsNoErr;
Ipp8u* pSrc = NULL; /* Pointers to source/destination/feature images */
int srcStep = 0; /* Steps, in bytes, through the source/destination/feature images */
IppiSize roiSize = { WIND_WIDTH, WIND_HEIGHT }; /* Size of source ROI in pixels */
const Ipp8u borderValue = 0;
IppiHOGSpec* pHOGctx = NULL; /* Pointer to the HOG context */
int hogCtxSize = 0, hogBuffSize = 0, winBuffSize = 0; /* Sizes of buffers */
Ipp8u* pBuffer = NULL; /* Pointer to the work buffer */
IppiPoint loc[] = { { 0, 0 }, { 2, 1 }, { 4, 2 }, { 6, 3 } }; /* Locations of detection window */
int numLocs = sizeof(loc) / sizeof(IppiPoint);
Ipp32f* pDescriptor = NULL; /* HOG descriptor */
check_sts( status = ippiHOGGetSize(&config, &hogCtxSize) ) /* Get size of HOG context */
pHOGctx = (IppiHOGSpec*)ippsMalloc_8u(hogCtxSize);
check_sts( status = ippiHOGInit(&config, pHOGctx) ) /* Initialize HOG context */
pSrc = ippiMalloc_8u_C1(roiSize.width, roiSize.height, &srcStep);
/* Compute the temporary work buffer size */
check_sts( status = ippiHOGGetBufferSize(pHOGctx, roiSize, &hogBuffSize) )
pBuffer = ippsMalloc_8u(hogBuffSize);
/* Compute size of HOG descriptor */
check_sts( status = ippiHOGGetDescriptorSize(pHOGctx, &winBuffSize) )
pDescriptor = (Ipp32f*)ippsMalloc_8u(numLocs*winBuffSize);
check_sts( status = ippiHOG_8u32f_C1R(pSrc, srcStep, roiSize, /* Compute HOG descriptor */
loc, numLocs, pDescriptor, pHOGctx, ippBorderConst, borderValue, pBuffer) )
EXIT_MAIN
ippiFree(pSrc);
ippsFree(pHOGctx);
ippsFree(pBuffer);
ippsFree(pDescriptor);
printf("Exit status %d (%s)\n", (int)status, ippGetStatusString(status));
return (int)status;
}