Welcome new user! You can search existing questions and answers without registering, but please register to post new questions and receive answers. Note that due to large amounts of spam attempts, your first three posts will be manually moderated, so please be patient.
Because of un-manageable amounts of spam despite our use of CAPTCHAs, email authorization, and other tools, we have discontinued this forum (see the 700k+ registered users with validated email addresses at right?). Please email us any questions or post bug reports and feature requests on GitHub at https://github.com/jevois -- The content below remains available for future reference.

Missing binding in python : rescaleCV

0 votes

Hi

I just played with new jevois-inventor and it's just amazing !! Great stuff indeed

Obviously, it becomes incredibly natural to add new python modules with that tool and I think I have discovered a missing binding in python that would be useful (at least in my app) : rescaleCv

when I do a pyhton jevois.rescaleCv(...) I get an error 'module libjevois' has no attribute rescaleCv

In think in file PythonSupport.C there is a missing

JEVOIS_PYTHON_RAWIMAGE_FUNC(rescaleCV);

Or maybe I am making another mistake ?

If you confirm the function is not exported in python, glurk ... 

Adding the missing binding (supposing I have the proper fix) and then recompiling all jevois-sdk is a task out of my league ...

If the issue is confirmed, any trick , any workaround ?

Thx

asked Jun 22, 2018 in Programmer Questions by acharroux (140 points)

1 Answer

0 votes

oh, thanks, we will check and add the binding, but 1.8.1 is frozen now (compiling the debs rihght now...) so that will be for 1.8.2.

Now do not despair, jevois::rescaleCv() is only a trivial wrapper over cv::resize(), which just chooses a different interpolation method depending on whether we are upscaling or downscaling:

cv::Mat jevois::rescaleCv(cv::Mat const & img, cv::Size const & newdims)
{
  cv::Mat scaled;

  if (newdims.width == img.cols && newdims.height == img.rows)
    scaled = img;
  else if (newdims.width > img.cols || newdims.height > img.rows)
    cv::resize(img, scaled, newdims, 0, 0, cv::INTER_LINEAR);
  else
    cv::resize(img, scaled, newdims, 0, 0, cv::INTER_AREA);

  return scaled;
}

so, in Python, you should be able to just do something along the lines of:

res = cv2.resize(img, (2*width, 2*height), interpolation = cv.INTER_CUBIC)

(I got that example from https://docs.opencv.org/3.4.0/da/d6e/tutorial_py_geometric_transformations.html )

answered Jun 22, 2018 by JeVois (46,580 points)
Great ! I did not understand it was a wrapper so tiny !!
Thx for the fast and accurate answer !!
...