2017-01-02 14 views
0

인텔 IPP가 이미지 크기 조정/변환 속도를 확인하기 위해 다음 코드를 시도했지만 끝에있는 ippsFree (pSpec)에서 계속 충돌합니다. 이유를 알 수 없습니다.인텔 IPP ippsFree() 충돌이 발생했습니다.

#include <stdint.h> 
#include <memory> 
#include <Windows.h> 
#include <time.h> 

#include "ipp.h" 

int main(...) { 
    srand(time(NULL)); 

    int width = 640; 
    int height = 480; 
    int channels = 2; 
    IppiResizeYUV422Spec* pSpec; 
    IppiSize dstSize, srcSize; 
    IppiPoint dstOffset = { 0, 0 }; 
    srcSize.width = width; 
    srcSize.height = height; 
    dstSize.width = 2 * width; 
    dstSize.height = 2 * height; 
    std::unique_ptr<unsigned char[]> sourceData; 
    std::unique_ptr<unsigned char[]> destinationData; 
    std::unique_ptr<unsigned char[]> destinationDataRGB; 
    std::unique_ptr<unsigned char[]> workBuffer; 

    sourceData.reset(new unsigned char[srcSize.width * srcSize.height * channels]); 
    destinationData.reset(new unsigned char[dstSize.width * dstSize.height * channels]); 
    destinationDataRGB.reset(new unsigned char[dstSize.width * dstSize.height * 3]); 
    workBuffer.reset(new unsigned char[dstSize.width * dstSize.height * channels]); 

    memset(sourceData.get(), 0, srcSize.width * srcSize.height * channels); 
    memset(destinationData.get(), 0, dstSize.width * dstSize.height * channels); 
    memset(workBuffer.get(), 0, dstSize.width * dstSize.height * channels); 

    IppStatus error; 
    int specSize = 0, initSize = 0, buffSize = 0; 
    error = ippiResizeGetSize_8u(srcSize, dstSize, IppiInterpolationType::ippNearest, 0, &specSize, &initSize); 

    pSpec = (IppiResizeYUV422Spec*) ippsMalloc_8u(specSize); 
    error = ippiResizeYUV422NearestInit(srcSize, dstSize, pSpec); 

    IppiRect srcRoi = { 0, 0, srcSize.width, srcSize.height }; 

    int64_t timerIPP9 = 0; 
    LARGE_INTEGER start, end; 
    LARGE_INTEGER tps; 
    QueryPerformanceFrequency(&tps); 

    for (unsigned int index = 0; index < 100; ++index) { 
     for (unsigned int imageIdx = 0; imageIdx < srcSize.width * srcSize.height * channels; ++imageIdx) { 
      sourceData.get()[imageIdx] = (rand() & 0xFF); 
     } 

     QueryPerformanceCounter(&start); 
     error = ippiResizeYUV422Nearest_8u_C2R(
      sourceData.get(), 
      srcSize.width * channels, 
      destinationData.get(), 
      dstSize.width * channels, 
      dstOffset, 
      dstSize, 
      pSpec, 
      workBuffer.get()); 
     QueryPerformanceCounter(&end); 

     timerIPP9 += end.QuadPart - start.QuadPart; 

     QueryPerformanceCounter(&start); 
     ippiYCbCr422ToRGB_8u_C2C3R(destinationData.get(), dstSize.width * channels, destinationDataRGB.get(), dstSize.width * 3, dstSize); 
     QueryPerformanceCounter(&end); 

     timerIPP9 += end.QuadPart - start.QuadPart; 
     printf("Test: %d, time: %d ms\r", index, timerIPP9 * 1000/tps.QuadPart); 
    } 

    ippsFree(pSpec); 
    printf("\n"); 
    printf("Time taken: %d ms\n", timerIPP9 * 1000/tps.QuadPart); 
    system("Pause"); 
    return 0; 
} 

난 변환기로 무작위 데이터를 파이핑하고 있지만 노이즈를 처리 할 수 ​​있어야합니다 (여전히 유효한 이미지이므로). 내가 퍼즐을 해결 생각

+0

최신 Intel IPP 2017.1.143 – SinisterMJ

+0

할당 후 바로 해제 해 보셨습니까? 오류 응답을 확인하는 것처럼 보이지 않습니다. (부인 : 인텔 IPP를 한번도 사용하지 않았습니다.) – owacoder

+0

인텔 IPP를 사용한 적이 한번도 없습니다. 문제는 여러분이'pSpec' 버퍼 밖에서 어떻게 든 씁니다. 그러면'ippsFree'를 호출 할 때이를 알 수 있습니까? – gurka

답변

1

...

당신이 코드처럼 다음 대체 할 필요 : 따르면

error = ippiResizeYUV422GetSize(srcSize, dstSize, IppiInterpolationType::ippNearest, 0, &specSize, &initSize); 

다음 하나

error = ippiResizeGetSize_8u(srcSize, dstSize, IppiInterpolationType::ippNearest, 0, &specSize, &initSize); 

을 IPP 문서로 :

설명 이 함수는 가장 가까운 이웃 보간 방법을 사용하여 크기 조정 알고리즘의 IppiResizeYUV422Spec 구조를 초기화합니다.
spec 구조체 객체의 크기를 계산하려면 ippiResizeYUV422GetSize 함수를 호출하십시오.

은 참조 : http://hpc.ipp.ac.cn/wp-content/uploads/2015/12/documentation_2016/en/ipp/common/ipp_manual/GUID-15B51AB0-7F73-4E13-AC81-753259CE0E2C.htm

ippiResizeYUV422GetSize을 실행 specSize의 값은 11776 같습니다.
ippiResizeGetSize_8u을 실행할 때 specSize의 값은 9240과 같습니다.
할당 된 크기가 작을수록 힙이 손상됩니다.