Ask Your Question
0

OpenCV: Replace ilLoadImage with cv::imread

asked 2017-03-29 03:32:42 -0600

lovaj gravatar image

I'm using hessgpu for efficiently compute hessian-affine SIFT descriptors using GPUs.

In this project, Devil is used for reading images: if SiftGPU::RunSIFT(const char *imgpath) is called (implemented here), then ilLoadImage is used in GLTexImage.cpp for reading images (as RGB images).

However, in my project I use cv::imread to read images. The project provides SiftGPU::RunSIFT(int width, int height, const void * data, unsigned int gl_format, unsigned int gl_type) to compute descriptors from data provided directly from the user.

So I tried:

cv::Mat img = cv::imread("image.jpg", cv::IMREAD_GRAYSCALE);
sift.RunSIFT(img.cols, img.rows, img.data, GL_LUMINANCE, GL_UNSIGNED_BYTE);

But this produce slightly less keypoints than sift.RunSIFT("image.jpg");. I tried to use:

cv::Mat img = cv::imread("image.jpg");
sift.RunSIFT(img.cols, img.rows, img.data, GL_RGB, GL_UNSIGNED_BYTE);

But this produces 0 keypoints, so something very wrong happens. I think:

  1. iLoadImage uses RGB image, while the only working method that I found up to now using cv::imread works only with grayscale images.
  2. It's possible that devil use a different process to read images than OpenCV, espcecially for RGB images (since using the second approach produced 0 keypoints).

How can I do the equivalent of ilLoadimage using cv::imread?

edit retag flag offensive close merge delete

Comments

Cross-post (posted at almost the same time...): OpenCV: Replace ilLoadImage with cv::imread

Eduardo gravatar imageEduardo ( 2017-03-29 04:38:56 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2017-03-29 03:37:45 -0600

berak gravatar image

updated 2017-03-29 03:44:22 -0600

  1. why ? cv::imread("image.jpg", cv::IMREAD_COLOR); would return a BGR image. (note, that you'd have to adjust the glflag to GL_BGR !)
  2. jpeg is a lossy format. don't expect exact same results with different libs/os using that (try with png for comparable results)
edit flag offensive delete link more

Comments

@berak I didn't know that, thanks for the tip! sift.RunSIFT(img.cols, img.rows, img.data, GL_RGB, GL_UNSIGNED_BYTE); solved the problem and produced the exact same amount of descriptors.

lovaj gravatar imagelovaj ( 2017-03-29 08:57:46 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2017-03-29 03:32:42 -0600

Seen: 241 times

Last updated: Mar 29 '17