2D convolution using openCV in C

陌路散爱 提交于 2019-12-08 09:23:46

问题


I want to implement a program which performs the 2D convolution using openCV. I'm new with openCV. my naive implementation is here:

#include <stdio.h>
#include <cv.h>
//used for kernel
unsigned short int kernel[3][3] __attribute__(( aligned(32)));                                          
// input and output image
unsigned short int input[512][512] __attribute__(( aligned(32)));
unsigned short int output[512][512] __attribute__((aligned(32)));

int main()
{
    //data are assigned to input and kernel matrices before.
    const CvArr* src = input;
    CvArr* dst = output;
    const CvMat* kernel = kernel; // return error incompatible pointer type
    CvPoint anchor=cvPoint(-1,-1); // ? 
    cvFilter2D(src,  dst, kernel, anchor); // want to multiply the kernel as it should do in 2D convolution program

    return 0;
}

I know it's not correct. can anyone help me to correct this implementation? I also can not understand the anchor! I studied and searched many links, these links might be helpful: 2D matrices with CvMat in OpenCV CvMat Struct Reference the C implementation of convolution program can be seen in this question: Fast 2D Convolution in C

I use gcc, Linux mint and Skylake

The build command is gcc -Wall pkg-config --libs opencv pkg-config --cflags opencv -march=native -D _GNU_SOURCE -O2 -o "%e" "%f"

I use -D _GNU_SOURCE to assign the program to a single core of the CPU. Is it correct to restrict the openCV? Because I want to check the performance on a single core.

UPDATE The goal of this implementation is a comparison between My Convolution implementation with another fast implementation on CPU. Is comparing to openCV a good idea? If not what is the best way? If yes is there any differences between C, C++ and java version for comparison? I mean my basic program is written in C does it make any sense to compare the program with C++ which uses g++ instead gcc and of course objects, etc.

来源:https://stackoverflow.com/questions/42987554/2d-convolution-using-opencv-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!