Rotate Camera Image only, blend with Image from Animation

Rotating an image is not normally a complicated matter. However, I have a somewhat complicated problem:

  1. I get an image from a live camera
  2. I read an image from an animation
  3. I mix the images with blend and then show them on the screen

After a defect, the camera was replaced, but mounted upside down. I just wanted to rotate only the camera image using software before blending it … but how?

if(anima.available()){anima.read();}
if(camera.available()){camera.read();}
      
      camimg=camera.get(xd+xa,yd+ya,ww,hh);
      camimg.resize(dw,dh);
     
      aniimg=anima.get(0,0,anima.width,anima.height);
      aniimg.resize(dw,dh);

      aniimg.blend(camimg, 0, 0, dw, dh, 0, 0, dw, dh, MULTIPLY); 
      image(aniimg,0,0);

One way:

I have written code in the past to flip, mirror, rotate etc.

:)

thanks, have found, works … flip two axis is like rotate 180 degree

PImage flip_img(PImage imx)
{
  int wid = imx.width;
  int hig = imx.height;
  PImage ret = new PImage(wid,hig);
  
  for(int x=0; x<wid; x++)
  {
    for(int y=0; y<hig; y++)
    {
      ret.set(wid - 1 - x, hig - 1 - y , imx.get(x,y));
    }
  }
  return ret;
}
1 Like

Another way:

String url = "http://learningprocessing.com/code/assets/sunflower.jpg";
PImage img;
PGraphics pg;

void setup()
  {
  size(400, 200);  
  img = loadImage(url);
  image(img, 0, 0);

  pg = createGraphics(img.width, img.height);
  pg.beginDraw();
  pg.translate(pg.width, 0);
  pg.scale(-1, 1);
  pg.image(img, 0, 0);
  pg.endDraw();
  
  image(img, 0, 0);
  image(pg, width/2, 0);
  noLoop();
  }

image

:)