ermig1979 / Simd

C++ image processing and machine learning library with using of SIMD: SSE, AVX, AVX-512, AMX for x86/x64, VMX(Altivec) and VSX(Power7) for PowerPC, NEON for ARM.
http://ermig1979.github.io/Simd
MIT License
2.01k stars 407 forks source link

How to use Simd::Integral with imread image from Opencv #231

Closed minhvogremsy closed 1 year ago

minhvogremsy commented 1 year ago

Please help me how to read image with opencv and add it to Simd::Integral. Thanks you!

ermig1979 commented 1 year ago

There is a simple example:

#define SIMD_OPENCV_ENABLE
#include "Simd/SimdLib.hpp"
typedef Simd::View<Simd::Allocator> View;
int main()
{
    cv::Mat cvSrc = imread("image.jpg", IMREAD_GRAYSCALE);
    View simdSrc = cvSrc;
    View simdInt(simdSrc.width + 1, simdSrc.height + 1, View::Int32);
    Simd::Integral(simdSrc, simdInt);
    cv::Mat cvInt = simdInt;
    return 0;
}
minhvogremsy commented 1 year ago

But I have an error Simd/SimdLib.hpp:2392: void Simd::Integral(const Simd::View&, Simd::View&) [with A = Simd::Allocator]: Assertion `src.format == View::Gray8 && sum.format == View::Int32' failed. Aborted (core dumped) olga-kononenko-HkyzJaoJLHw-unsplash

ermig1979 commented 1 year ago

It seems that function imread("image.jpg", IMREAD_GRAYSCALE); reads image in format different from 8-bit gray. Perhaps there is need to additional conversion of input image to 8-bit gray because Simd::Integral works only with 8-bit gray input images.