Hi, I am new to fastcv forum. I am trying to implement fastcv multiplication api from opencv. Below is my code. I am not getting the expected output from fastcv api. I don't know how to implement a fcv multiplication with scalar value 1.0 like opencv multiply. so please help me on my below queris;
1. How to implement fcv multiply like this (cv::multiply(src, 1.0, bitBuffer, 1.0, CV_16U))
2. Anyhow for output of opencv and fcv multiply for 1st one is getting same result and size is also same. But for 2nd multiply for both which is mentioned below, i am not getting the same output.
Below is my code. Thanks in advance for any help.
OPENCV Multiplication:
Mat src = cv::imread("/storage/emulated/0/fastcvTesting/activesight.jpg", cv::IMREAD_GRAYSCALE);
Mat bitBuffer = Mat(srcHeight, srcWidth, CV_16U); ////multiplication with scalar value 1.0 cv::multiply(src, 1.0, bitBuffer, 1.0, CV_16U); src=bitBuffer; cv::imwrite("/storage/emulated/0/fastcvTesting/opencvmultiplywith1_0.jpg",bitBuffer); Mat squareBuffer= Mat(srcHeight, srcWidth, CV_32F); cv::multiply(src, src, squareBuffer); cv::imwrite("/storage/emulated/0/fastcvTesting/opencvmultiplywithsameinput.jpg",squareBuffer);
FASTCV MULTIPLICATION:
Mat inputsrc = cv::imread("/storage/emulated/0/fastcvTesting/activesight.jpg", cv::IMREAD_GRAYSCALE); const uint8_t* __restrict src= inputsrc.data; /// multiplication with scalar value 1.0 Mat bitBuffer= inputsrc * 1.0; bitBuffer.convertTo(bitBuffer, CV_16U); uint8_t *__restrict bitBufferdata= bitBuffer.data; src=bitBufferdata; cv::imwrite("/storage/emulated/0/fastcvTesting/fcvmultiplywith1_0.jpg", bitBuffer); /////Multiplication of same input src uint8_t * __restrict squareBufferdata= new uint8_t[srcWidth * srcHeight*4]; fcvElementMultiplyu8(src, srcWidth*3, srcHeight, 0,src,0,1,FASTCV_CONVERT_POLICY_SATURATE,squareBufferdata,0 ); Mat squareBuffer= Mat(srcHeight, srcWidth, CV_16U, squareBufferdata); cv::imwrite("/storage/emulated/0/fastcvTesting/fastcvmultiplywithsameinput.jpg",squareBuffer);
Hi,
There could be saturation that causes the mismatch.
Recommend to use U16 type for the squared output, and the following API:
fcvElementMultiplyu8u16
Best,
-Jeff
Thanks jeff. after implimenting "fcvElementMultiplyu8u16", i got the expected output. But i am not understanding how to implement "cv::multiply(src, 1.0, bitBuffer, 1.0, CV_16U)" by using fastcv.
Where bitBuffer: Mat bitBuffer = Mat(srcHeight, srcWidth, CV_16U);
Could you please help me here.