Forums - Fastcv multiplication with scalar value

3 posts / 0 new
Last post
Fastcv multiplication with scalar value
rchanda
Join Date: 8 Jun 20
Posts: 7
Posted: Thu, 2020-08-27 05:05

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.0CV_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);
  • Up0
  • Down0
jeff4s Moderator
Join Date: 4 Nov 12
Posts: 106
Posted: Thu, 2020-08-27 18:55

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

  • Up0
  • Down0
rchanda
Join Date: 8 Jun 20
Posts: 7
Posted: Tue, 2020-09-01 03:29

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.

  • Up0
  • Down0
or Register

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.