Ask Your Question

Dayama Pradeep's profile - activity

2020-01-28 08:43:57 -0600 received badge  Famous Question (source)
2018-09-27 09:48:59 -0600 received badge  Notable Question (source)
2018-06-01 05:27:38 -0600 received badge  Popular Question (source)
2015-11-08 22:20:02 -0600 received badge  Enthusiast
2015-11-06 04:00:28 -0600 commented question coversion of image from uchar to float

Sorry guys, Actually i was not getting proper output so i was doubting my image conversion from uchar to float, the logic for conversion which i arrived after a pretty long discussion with @berak is right. the problem which i rectified is with the Logic i applied for image processing @boaz001 Image processing i m doing on image is to findout minumum of RGB in an image and make it a single channel image, after this Add a patch to image with patch size of 15x15, and find minimum value of current pixcel in that patch, then move the patch further. This is the image processing Stuff i m doing. Error which I encountered during image processing is, the output should be a Dark Gray Scale image, but what I was getting is a Full Blank image as that of Blank Computer monitor after shut down

2015-11-05 01:14:39 -0600 commented question coversion of image from uchar to float

@berak, the reason i want to convert image into float is coz the processing of image will be more precise. After that previous disscusion we had on the same topic, i use the logic for conversion what we discussed then, but i t seems to be failed at the time of image processing

2015-11-05 00:57:36 -0600 commented question coversion of image from uchar to float

@berak, Hello again.. we had this same discussion on conversion of char to float here is the discuddion but when i do some image processing operation on that converted image i get problems

2015-11-05 00:22:52 -0600 asked a question coversion of image from uchar to float

Hello

I m trying to convert an image from uchar to float but i get an error as Assertion failed

here is my code snippet

#include <stdio.h>
#include "opencv2/opencv.hpp"

using namespace cv;
using namespace std;

 Mat img = imread(img_name);

 if (img .empty()) 
{ 
    cerr << "no image"; return -1; 
}

 height = img.rows;
 width = img.cols;
 size = img.rows*img.cols;

 float* cpu_image = (float *)malloc((size+1) * 3 * sizeof(float));
 if (!cpu_image)
 {
    std::cout << "ERROR: Failed to allocate memory" << std::endl;
    return -1;
  }

  //converting image from uchar to float* pixcel-wise
  for (int i = 0; i < height; i++){
    for(int j = 0; j < width; j++)
    {
        for(int k = 0; k < 3; k++){
            cpu_image[(i * width + j) * 3 + k] = img.at<Vec<float,3> >(i,j)[k];
        }
    }
}
cpu_image[size] = 0;
cpu_image[size+1] = 0;
cpu_image[size+2] = 0;

    //converting image back to uchar from float
    Mat dest(height, width, CV_32FC3, cpu_image);
    imwrite(out_name, dest);

   free(cpu_image);

   return 0;

  }

Any advice pls...

2015-10-29 06:09:55 -0600 commented question Problem in conversion from float* to cv::mat

@berak i couldn't get you.. The code has successfully worked for me.. you add the answer it i feel like somethings needed to be changed i ll edit it..

2015-10-29 02:22:33 -0600 commented question Problem in conversion from float* to cv::mat

@beark please also let me know if there is any material available to learn IMAGE PROCESSING and PROGRAMMING USING OPENCV

2015-10-29 02:21:05 -0600 commented question Problem in conversion from float* to cv::mat

@beark I cant post the answer by myself fpr 24 hours,

so here is the final code

#include<iostream>
#include<opencv2/opencv.hpp>

using namespace std;
using namespace cv;

int main()
{
 //load the image
 Mat src = imread("foggyHouse.jpg");

//read height, width data
int height = src.rows;
int width = src.cols;

//check whether image loaded is empty or not.
if (src.empty()) 
{ 
    cerr << "no image"; return -1; 
}

//convert image from CV::MAT to float*.
Mat dst;
src.convertTo(dst, CV_32F);
float *data = dst.ptr<float>();

//convert back the image from float* to CV::MAT.
Mat dest(height, width, CV_32FC3, data);

//print the image
imwrite("IMg.jpg", dest);

return 0;
}
2015-10-29 02:01:41 -0600 commented question Problem in conversion from float* to cv::mat

@beark Thanks a lot... finally i m getting the output as i need.. i ll reply to my question.. i.e. i ll add the answer myself.. please check it..

2015-10-28 04:55:53 -0600 commented question Problem in conversion from float* to cv::mat

sorry I didn't said you prior, In the above code I'm using imshow for source file, which results in displaying the image and hence the image is getting loaded properly

2015-10-28 04:04:42 -0600 commented question Problem in conversion from float* to cv::mat

Edited the question.. Please check it @berak

2015-10-28 04:03:36 -0600 received badge  Editor (source)
2015-10-28 02:57:22 -0600 commented question Problem in conversion from float* to cv::mat

I tried converting as you said i.e. using CV_8U but i get a error saying

First-chance exception at 0x528E0A14 (opencv_world300.dll) in Project3.exe: 0xC0000005: Access violation reading location 0x00137000. Unhandled exception at 0x528E0A14 (opencv_world300.dll) in Project3.exe: 0xC0000005: Access violation reading location 0x00137000.

code snippet is here

Mat dest;
dst.convertTo(dest,CV_8U);

i have also tried with other formats like CV_8UC1, CV_8UC3 etc.. but all gives same error

2015-10-28 02:28:38 -0600 commented question Problem in conversion from float* to cv::mat

That's great..!! Its working..

But how do i convert back to cv::mat(string), such that i can print an image using imwrite

my plan was to convert an image from cv::mat to float*, do some image processing, again convert back to cv::mat and print it

for converting it to cv:mat i m using this

Mat dest(height, width, CV_32FC1, data);

is this fine?? i mean, am i heading in correct direction??

2015-10-28 01:49:26 -0600 asked a question Problem in conversion from float* to cv::mat

Hello I'm using VS2013 and openvc 3.0

Here I'm trying to read an image, convert it to float* from CV::MAT, do some processing, and again convert it back to CV::MAT from float* Here is the code snippet

  `
   #include<iostream>
    #include<opencv2/opencv.hpp>

   using namespace std;
   using namespace cv;

   int main()
  { 
        //read the image
        Mat src = imread("foggyHouse.jpg");

       //convert to float*
        Mat dst;
    src.convertTo(dst, CV_32F);
        float *data = dst.ptr<float>();

       //convert back to CV::MAT from float*
       Mat dest;
   dst.convertTo(dest,CV_8U);

      //print image
       imwrite("IMg.jpg", dest);

    return 0;
 }

` the problem is I'm getting an error saying

First-chance exception at 0x528E0A14 (opencv_world300.dll) in Project3.exe: 0xC0000005: Access violation reading location 0x00137000. Unhandled exception at 0x528E0A14 (opencv_world300.dll) in Project3.exe: 0xC0000005: Access violation reading location 0x00137000.

i tried other method to convert from CV:MAT to float* here is the code

int height = src.rows;
int width = src.cols;

   //convert from CV::MAT to float*
Mat dst;
src.convertTo(dst, CV_32F);
float *data = dst.ptr<float>();

    //convert from float*  to CV::MAT
    Mat dest(height, width, CV_32FC1, data);
imwrite("IMg.jpg", dest);

this is also giving the same error

Any suggestion or help will be appreciated.

Thanks