Forums - data type conversion

5 posts / 0 new
Last post
data type conversion
371152061
Join Date: 13 May 22
Posts: 11
Posted: Sun, 2022-05-22 18:49

Hi,

     I want to make conversion from uint8_t* to float32_t*  (or float64_t*)  in fastcv,  uint8_t* is a  RGB image,  float32_t* is 4 times the size than uint8_t*.

can anyone tell me how to implement it, thanks~~

     Here is the opencv code.   (mat_float thats I want)

cv::Mat mat = cv::imread("/sdcard/Vms_out/1.jpg");
mat.convertTo(mat_float, CV_32FC3);
  • Up0
  • Down0
371152061
Join Date: 13 May 22
Posts: 11
Posted: Mon, 2022-05-23 03:22
does it works?
    
uint8_t *img = (uint8_t *)fcvMemAlloc(w*h, 16);
//ARGB->RGB gray
fcvColorRGB888ToGrayu8 ((uint8_t*)rgb888, src_width, src_height, 0, (uint8_t*)img, 0);
 
float *I = (float *)fcvMemAlloc(w*h*4, 16);
for(int i=0; i<w*h; i++) {
*(I+i) = (float)(*(img+i))/255.0;
}
  • Up0
  • Down0
371152061
Join Date: 13 May 22
Posts: 11
Posted: Mon, 2022-05-23 03:23
does it works?
    
uint8_t *img = (uint8_t *)fcvMemAlloc(w*h, 16);
//ARGB->RGB gray
fcvColorRGB888ToGrayu8 ((uint8_t*)rgb888, src_width, src_height, 0, (uint8_t*)img, 0);
 
float *I = (float *)fcvMemAlloc(w*h*4, 16);
for(int i=0; i<w*h; i++) {
*(I+i) = (float)(*(img+i))/255.0;
}
  • Up0
  • Down0
xtang
Join Date: 6 Dec 21
Posts: 12
Posted: Tue, 2022-05-31 20:13

 

below code should work:

            -- uint8_t *img = (uint8_t *)fcvMemAlloc(w*h, 16);

            ++ uint8_t *img = (uint8_t *)fcvMemAlloc(w*h, sizeof(uint8_t));

            //ARGB->RGB gray

           // fcvColorRGB888ToGrayu8 ((uint8_t*)rgb888, src_width, src_height, 0, (uint8_t*)img, 0); 

 

            -- float *I = (float *)fcvMemAlloc(w*h*4, 16);

            ++ float *I = (float *)fcvMemAlloc(w*h*4, sizeof(float));  // The size of float is 4.

            for(int i=0; i<w*h; i++) {

                        *(I+i) = (float)(*(img+i))/255.0;

            }

 

not sure why you call fcvColorRGB888ToGrayu8(), I think no need call it.

Thanks,

Xiaofeng

 

  • Up0
  • Down0
371152061
Join Date: 13 May 22
Posts: 11
Posted: Wed, 2022-06-01 07:08

1.   I use java to read the jpg file with ARGB,  so should go flow: ARGB->RGB888->gray

2.  I will scale down the gray image, the src should be aligned to 128 bit, so

                       uint8_t *img = (uint8_t *)fcvMemAlloc(w*h, 16);

  • 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.