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_007int main(int argc, char *argv[]){int32_t fd = -1;// src raw data bufferuint8_t src[Z_IMG * X_IMG * Y_IMG] = {0};printf("Allocating memory for tempdst\n");// destination data bufferuint8_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 ?