Forums - fcvMemAlloc fails in a Segmentation Fault

1 post / 0 new
fcvMemAlloc fails in a Segmentation Fault
simozz
Join Date: 7 Apr 17
Posts: 4
Posted: Thu, 2018-01-11 12:02
Hello, 
 
I am a newbie with fastcv and I am trying to running a simple C code for Linux. The purpose is to read a RGB raw data from an external file, perform a gaussian blur filtering an storing the result in another fiile, always as raw data.
 
The code I wrote is this one:
 
// compile with gcc file.c -o file -I <fastcv_inc_dir> -L <fastcv_lib_dir> -lfastcv  -lm -lpthread -O3
 
#ifndef _USE_MATH_DEFINES
#define _USE_MATH_DEFINES
#endif
 
#ifndef _GNU_SOURCE
#define _GNU_SOURCE
#endif
 
#include <stdio.h>
#include <unistd.h>
#include <stdint.h>
#include <math.h>
#include <sys/file.h>
#include <fcntl.h>
 
#define NDEBUG
#include <fastcv.h>
 
#define Z_IMG 3
#define Y_IMG 1280
#define X_IMG 960
 
#define INPUT_FILE_NAME (const char *) "rgb.raw"
#define OUTPUT_FILE_NAME (const char *) "blurred.raw"
 
#define MODE_700 (mode_t) S_IRWXU // 00700
#define MODE_400 (mode_t) S_IRUSR // 00400
#define MODE_200 (mode_t) S_IWUSR // 00200
#define MODE_100 (mode_t) S_IXUSR // 00100
#define MODE_070 (mode_t) S_IRWXG // 00070
#define MODE_040 (mode_t) S_IRGRP // 00040
#define MODE_020 (mode_t) S_IWGRP // 00020
#define MODE_010 (mode_t) S_IXGRP // 00010
#define MODE_007 (mode_t) S_IRWXO // 00007
#define MODE_004 (mode_t) S_IROTH // 00004
#define MODE_002 (mode_t) S_IWOTH // 00002
#define MODE_001 (mode_t) S_IXOTH // 00001
 
#define MODE_777 (mode_t) MODE_700 | MODE_070 | MODE_007
 
int main(int argc, char *argv[])
{
    int32_t fd = -1;
 
    // src raw data buffer
    uint8_t src[Z_IMG * X_IMG * Y_IMG] = {0};
 
    printf("Allocating memory for tempdst\n");
    // destination data buffer
    uint8_t *tempdst = (uint8_t*) fcvMemAlloc(Z_IMG * X_IMG * Y_IMG * sizeof(uint8_t), 16);
 
    printf("opening %s\n", argv[1]);
    fd = open(argv[1], O_RDONLY);
    if(fd == -1)
    {
        perror("open: ");
        return -1;
    }
    
    printf("Reading...");
    read(fd, src, sizeof(src));
    close(fd);
    fd = -1;
 
    fcvFilterGaussian11x11u8(src, 1280, 960, tempdst, 1);
 
    printf("Writing...");
    fd = open(OUTPUT_FILE_NAME, O_RDWR | O_CREAT, MODE_777);
    write(fd, tempdst, Z_IMG * X_IMG * Y_IMG);
    close(fd);
 
    fcvMemFree(tempdst);
    printf("\n");
    return 0;
}
 
The problem I encounter is that the function fcvMemAlloc fails in a Segmentation Fault.
 
What do I have to do to run my code successfully ?
 
Thank you in advance.
 
Regards,
 
Simon
 
PS: I did not find any tutorial or sample code for fastcv. Would be possible to publish a few examples ?
  • Up0
  • Down0

Opinions expressed in the content posted here are the personal opinions of the original authors, and do not necessarily reflect those of Qualcomm Incorporated or its subsidiaries (“Qualcomm”). The content is provided for informational purposes only and is not meant to be an endorsement or representation by Qualcomm or any other party. This site may also provide links or references to non-Qualcomm sites and resources. Qualcomm makes no representations, warranties, or other commitments whatsoever about any non-Qualcomm sites or third-party resources that may be referenced, accessible from, or linked to this site.