Ask Your Question
1

is there any builtin Modulo function on Matices ?

asked 2016-11-02 05:51:48 -0600

azdoud.y gravatar image

updated 2016-11-02 06:26:50 -0600

I've a Mat object containing these orientation values (0 to 360), i want by using modulo operation to represent them between (0 to 180) range

   Mat a, b;
   ...
   b = mod(a,180); // x - floor(x/y) * y

didn't find it, i tried this instead

   void Modulo(Mat &angle, int val){
       for(int i = 0; i < angle.rows; i++){
          for(int j = 0; j < angle.cols; j++){
              // x - floor(x/y) * y
              float result = angle.at<float>(i,j) - cvFloor(angle.at<float>(i,j)/val) * val; 
              angle.at<float>(i,j) = result;
          }
       }
   }
edit retag flag offensive close merge delete

Comments

do you really need the "general" solution ? or would if v > 180 then v-= 180 do in your case?

berak gravatar imageberak ( 2016-11-02 06:58:50 -0600 )edit
1

general case would be better

azdoud.y gravatar imageazdoud.y ( 2016-11-02 07:01:22 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2016-11-02 07:06:35 -0600

berak gravatar image

updated 2016-11-02 07:34:03 -0600

i don't think, you need the general solution above, we can simply exploit, that there are max. 2 times 180 in 360, then it's:

Mat mask = angle > 180.0f;
subtract(angle, 180.0f, angle, mask);

or , in one line:

subtract(angle, 180.0f, angle, (angle>180.0f));

you can even run wild with c++11 here:

angle.forEach([&](float &f, const int *p) {f = fmod(f,180.0f);});
edit flag offensive delete link more

Comments

thank you for your answers and for your fast replaying i'll will choose the quickest one :D

azdoud.y gravatar imageazdoud.y ( 2016-11-02 07:41:09 -0600 )edit

thank you a lot #berak

azdoud.y gravatar imageazdoud.y ( 2016-11-02 07:52:52 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2016-11-02 05:51:48 -0600

Seen: 2,254 times

Last updated: Nov 02 '16