Pi 3 extremely slow performance drawing images

I’m not sure if I’m just overestimating the abilities of the Pi, but I’m trying to run a simple program to draw an artificial horizon, and while it runs buttery smooth on my desktop (normal windows 10 computer) as soon as I try to run it on the pi, the performance CRAWLS. Just over drawing a simple image…

I must be doing something wrong here? Why is it so slow? I’ve tried changing the render mode to fullscreen, which helped… but how is it that this thing can play minecraft at a smooth framerate and yet struggles to break 10fps drawing a single image over and over?

EDIT: I just realized I never attached the image. Use this one: https://imgur.com/a/QBVnmXG

Here is my code:

//mfd test for aircraft

PGraphics ghorizon;

float horizH = 250;
float horizR;
PImage img;
float testx;
float testy;


  
void setup() {
  fullScreen();
  img = loadImage("artificial horizon 2.png");
  ghorizon = createGraphics(550, 500);
  drawbg();
}

void draw() {
//  drawhorizon();
  drawhorizon2(200,60);
  testx = sin(float(frameCount)/100)*100;
  testy = sin(float(frameCount)/150)*100;
}

void drawbg() {
  background(0);
}

void drawhorizon2(int x,int y) {
  ghorizon.beginDraw();
//    ghorizon.background(0);
    ghorizon.translate(275,250);
    ghorizon.rotate(radians((testx))/4);
    ghorizon.translate(0,testy);

    ghorizon.image(img,-500,-1250);

  ghorizon.endDraw();
  
  
  image(ghorizon,x,y);
  
  stroke(0);
  noFill();
  strokeWeight(20);
  rect(x-10,y-10,570,520,40);
  
  stroke(255);
  strokeWeight(12);
  line(x+150,y+250,x+220,y+250);
  line(x+220,y+250,x+220,y+270);
  line(x+330,y+250,x+400,y+250);
  line(x+330,y+250,x+330,y+270);
  
  stroke(0);
  strokeWeight(8);
  line(x+150,y+250,x+220,y+250);
  line(x+220,y+250,x+220,y+270);
  line(x+330,y+250,x+400,y+250);
  line(x+330,y+250,x+330,y+270);
  
  strokeWeight(3);
  stroke(255,0,255);
  line(x+275,y+175,x+275,y+325);
  line(x+200,y+250,x+350,y+250);
}

1 Like

-a- yes, fullscreen apps might get slow.
why not start 800*800

-b- put a FPS show into your sketch
or play with this tool

 float rset=120, r;
int x = 0;
int w = 400;
int h = 200;
int grid=20, many = grid*grid;
boolean stressenable=true;

void settings() {
  size(w, h); // default use JAVA2D 
  //  size(w, h,FX2D);
  //  size(w, h,P2D);
  //  size(w, h,P3D);
}

void setup() {
  frameRate(rset);
  background(200, 200, 0);
  numinfo();
  sysinfo();
  println("\nstresstest ( "+grid+"*"+grid+" = "+many+" ) points, [+][-] grid +-5" );
}

void draw() {
  surface.setTitle("SYS INFO set "+rset+": "+ nf(r, 0, 1)+" FPS" );
  if ( stressenable ) stress();
  r = frameRate;
  if ( r > 30 )      stroke(0, 200, 0); 
  else               stroke(200, 0, 0);
  line(x, height-2, x, height-2-r);            // FPS graph
  x++;
  if ( x > width ) { 
    x = 0; 
    background(200, 200, 0);
  }
}

void stress() {
  push();
  for ( int i=0; i<grid; i++) {
    for ( int j=0; j<grid; j++) {
      stroke(random(255), random(255), random(255) );
      point(5+i, 5+j);
    }
  }
  pop();
}

void sysinfo() {
  println( "__SYS INFO :");
  println( "System     : " + System.getProperty("os.name") + "  " + System.getProperty("os.version") );// + "  " + System.getProperty("os.arch") );
  println( "JAVA       : " + System.getProperty("java.home")  + " rev: " +javaVersionName);
  //println( System.getProperty("java.class.path") );
  //println( "\n" + isGL() + "\n" );
  println( "OPENGL     : VENDOR " + PGraphicsOpenGL.OPENGL_VENDOR+" RENDERER " + PGraphicsOpenGL.OPENGL_RENDERER+" VERSION " + PGraphicsOpenGL.OPENGL_VERSION+" GLSL_VERSION: " + PGraphicsOpenGL.GLSL_VERSION);
  println( "user.home  : " + System.getProperty("user.home") );
  println( "user.dir   : " + System.getProperty("user.dir") );
  println( "user.name  : " + System.getProperty("user.name") );
  println( "sketchPath : " + sketchPath() );
  println( "dataPath   : " + dataPath("") );
  println( "dataFile   : " + dataFile("") );
  println( "frameRate  : target "+nf(rset, 0, 1)+" actual "+nf(r, 0, 1));
  println( "canvas     : width "+width+" height "+height+" pix "+(width*height));
}

void numinfo() {
  println( "__NUM INFO :");
  println( "byte     "+Byte.SIZE+  " bit | min: "+Byte.MIN_VALUE+   "\t\t\t max: "+Byte.MAX_VALUE);
  println( "short   "+Short.SIZE+  " bit | min: "+Short.MIN_VALUE+  "\t\t\t max: "+Short.MAX_VALUE);
  println( "int     "+Integer.SIZE+" bit | min: "+Integer.MIN_VALUE+"\t\t max: "  +Integer.MAX_VALUE);
  println( "long    "+Long.SIZE+   " bit | min: "+Long.MIN_VALUE+   "\t max: "    +Long.MAX_VALUE);
  println( "float   "+Float.SIZE+  " bit | min: "+Float.MIN_VALUE+  "\t\t\t max: "+Float.MAX_VALUE);
  println( "double  "+Double.SIZE+ " bit | min: "+Double.MIN_VALUE+ "\t\t\t max: "+Double.MAX_VALUE);
}

void keyPressed() {
  if ( key == 's' ) stressenable = ! stressenable;
  if ( key == '+' ) {
    grid +=5;
    many = grid*grid;
    println("stresstest ( "+grid+"*"+grid+" = "+many+" ) points" );
  }
  if ( key == '-' ) {
    grid -=5;
    many = grid*grid;
    println("stresstest ( "+grid+"*"+grid+" = "+many+" ) points" );
  }
}


if you need me to test your code here, need some time.

1 Like

Hey! Thanks for replying! I just edited the post because I realized I was an idiot and forgot that part.

This is the image in question: https://imgur.com/a/QBVnmXG

I really want this to run at 1280x800, as that is the resolution of the screen. This is for a glass cockpit for my ultralight aircraft :slight_smile:

This is what it looks like right now:

Fullscreen actually improved the FPS slightly, I’m working on trying to figure out how to add an FPS counter to see how much it did…

2 Likes

please play my test tool

I just tried to run it, and it’s complaining that push() and pop() no longer exist?

ok,
lets start from the beginning,
? system hardware
? system software
? installed processing


you might study my picture,
but i posted it also for exactly that reason
you see my RASPBIAN sysinfo
processing version
Processing sysinfo

but just to be exact, it is the old / first buster setup updated,
( not the latest RASPBIAN / that i am still testing )
( all about the video GLvideo library problems now )

1 Like

Thank you so much for the help. It’s much appreciated. I’ve been working on this on and off for a while so I figure it is probably slightly out of date. Also I’m a huge noob at processing, it seems, so I might be a bit slow.

Main system: Win10, i7 6700k, blah blah, processing 3.4.

Problem system: Pi 3+, and whatever the raspbian version that comes pre-downloaded with processing 3.4 was… I’m not sure how to check.

I can see you’re on 3.5.3, which is probably part of the issue. I shall… go and update things, heh. Be right back with that.

1 Like

now i just look at that picture PNG you use,
1000 * 2500
for 2 color filled rectangle with some lines and numbers easy to do with FOR loop.
loose the picture!

yes, even with

void setup() {
  //fullScreen();
  size(500,500);

and

void draw() {
//  drawhorizon();
  background(0);
  text("FLUSI "+nf(frameRate,0,1)+" fps",10,10);
  drawhorizon2(200,60);

i only see 11 fps.

1 Like

It appears the latest official raspbian + processing download is still 3.4, so I’m not sure how to update it manually beyond that. (Not super experienced with linux)

Okay, I can try to implement it manually. I used to draw objects as a bunch of individual primitives, but that was slow as well. Please try this example: https://www.dropbox.com/s/2ksm79g3hl8kf2o/pi_dash_test.zip?dl=0

It runs great on my desktop, but only at 10.5fps on the pi.

Is the Pi just very slow or am I doing something stupid?

Thank you for being so fast to respond!

or both, sorry i not study your code,
but you should start with a new project
testing about FPS, fullscreen or
on a RPI 3B plus

void setup(){
 fullScreen();  // 13.5 fps
 //size(1920,1080);  // 12.3 fps
 //size(1000,1000);  // 23.3 fps
 //size(500,500);    // 59.fps

}

and start draw first items to get a better feeling.

Yeah… I might do that. Just don’t even really have much going on in this one either, and its already lagging. I removed the image and simply replaced it with a rectangle, and it goes just as slowly.

When I am talking about fps, in terms of the problem, I mean that it runs at a locked 30fps no problem on my win10 desktop, but struggles on the pi when uploaded and ran on it. Windowed, fullscreen, no matter what on the pi, it goes slowly. CPU usage on the pi also never goes high, right now its at 30% while running the sketch.

Try this:

//mfd test for aircraft

PGraphics ghorizon;

float horizH = 250;
float horizR;
PImage img;
float testx;
float testy;


  
void setup() {
  size(1280,800);
//  img = loadImage("artificial horizon 2.png");
  ghorizon = createGraphics(550, 500);
  drawbg();
}

void draw() {
//  drawhorizon();
  drawhorizon2(200,60);
  testx = sin(float(frameCount)/100)*100;
  testy = sin(float(frameCount)/150)*100;
}

void drawbg() {
  background(0);
}

void drawhorizon2(int x,int y) {
  ghorizon.beginDraw();
    ghorizon.background(0);
    ghorizon.translate(275,250);
    ghorizon.rotate(radians((testx))/4);
    ghorizon.translate(0,testy);

//    ghorizon.image(img,-500,-1250);
  ghorizon.stroke(255);
  ghorizon.fill(150);
  ghorizon.rect(0,0,400,400);
  ghorizon.endDraw();
  
  
  image(ghorizon,x,y);
  
  stroke(0);
  noFill();
  strokeWeight(20);
  rect(x-10,y-10,570,520,40);
  
  stroke(255);
  strokeWeight(12);
  line(x+150,y+250,x+220,y+250);
  line(x+220,y+250,x+220,y+270);
  line(x+330,y+250,x+400,y+250);
  line(x+330,y+250,x+330,y+270);
  
  stroke(0);
  strokeWeight(8);
  line(x+150,y+250,x+220,y+250);
  line(x+220,y+250,x+220,y+270);
  line(x+330,y+250,x+400,y+250);
  line(x+330,y+250,x+330,y+270);
  
  strokeWeight(3);
  stroke(255,0,255);
  line(x+275,y+175,x+275,y+325);
  line(x+200,y+250,x+350,y+250);
}

LOL

lets say, processing cooks on one burner.

so unless your JOB could be divided in THREAD s
the single CPU speed will be your limit.
( and sorry, i never play about overclocking )
( i use from terminal htop )

1 Like

Ah, understood. I will do that and see what the result is.

While simply trying to wiggle a rectangle around, this is the htop picture:

2 Likes

yes, and fullscreen ( plus ALT TAB works )
( i work remotely VNC )

1 Like

Interesting… Even the act of drawing a rectangle and moving it around completely uses up a core on the pi. I’m not even sure how to deal with that other then ditching processing and trying to learn something else.

I can’t simplify it down more then just drawing a rectangle, which still lags it. I feel like this doesn’t make any sense. I guess I’ll try again from scratch.

Thank you for your help.

this would be python webserver on RPI
with dynamic data from Arduino ( PID control… )
here

or python app only
here

from
http://kll.engineering-news.org/kllfusion01/articles.php?article_id=125

but i would not dare to compare processing JAVA app with python app or even
python web app speed wise, too many parameter…

1 Like

That looks pretty slick! Did you make that?

I’ve never tried to use python before, so that will be a bit interesting. Do you have any pointers on where to start? (graphics libraries to use, that kind of thing, I googled it and there appears to be a lot…)