Notifications
Clear all

DevCPP and graphics.h

27 Posts
3 Users
2 Reactions
7,279 Views
robotBuilder
(@robotbuilder)
Member
Joined: 7 years ago
Posts: 2581
Topic starter  

@tfmccarthy

From the other thread.
https://forum.dronebotworkshop.com/user-robot-projects/robot-base-new-build/paged/7/#post-50813

ok tried again. looking at a video it says the official download doesn't compile and to use this one,
https://sourceforge.net/projects/orwelldevcpp/

The console program compiled and ran...

Using this link to install graphics.h
https://codolog.in/how-to-add-a-graphics-header-file-in-dev-c/?i=1

However the example failed to compile ...

To enlarge image, right click mouse and select Open link in new window.

devCPP ERROR


   
Quote
TFMcCarthy
(@tfmccarthy)
Member
Joined: 2 years ago
Posts: 518
 

@robotbuilder,

I understand your eagerness to "get on with it" ... but we need to be patient right now and stick to the first task of getting freeBasic working on both machines. Give me a couple of days. Trust me, we'll get to using the graphics lib and then on to more advanced graphics libraries.

From the quick glance I think I know the issue you have but it's a tangent right now.

 


The one who has the most fun, wins!


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 7 years ago
Posts: 2581
Topic starter  

@tfmccarthy 

I wasn't trying to hurry you up just giving you some information about installing FreeBASIC should you decide to give it a go or not. I have plenty of things to do both software wise, but mostly in real life, to keep me occupied 🙂

The reason I was interested in using C++ is because I used it all the time once although I don't use its more advanced features. It is the bedrock of software development and a must if you want complete control over your hardware. There is of course Assembler but C++ can run on different CPUs and I am told compiles to very efficient machine code these days.

The latest versions of FreeBASIC are the closest you can get to C++ IMHO and I can easily translate FB to C++ but not so easy to translate FB to Python which is a weird language.

The reason I was interested in learning Python basics was to share code algorithms with Python users like Byron and also to read all that Python software.

But it is all mainly a fun passtime like solving puzzles regardless of any success or not.

 



   
ReplyQuote
TFMcCarthy
(@tfmccarthy)
Member
Joined: 2 years ago
Posts: 518
 

Posted by: @robotbuilder
↑

I wasn't trying to hurry you up ...

Yes, Yes you did! You pushed me so hard I have a bruise and may cry.

Posted by: @robotbuilder
↑

... just giving you some information about installing FreeBASIC should you decide to give it a go or not.

Too late! Already installed and I'm running the examples to test the install. Have the IDE as well, but not likely to use it.

Once we have a few rounds of freeBasic behind us, we'll talk about upgrading to C++ if you're still interested.


The one who has the most fun, wins!


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 7 years ago
Posts: 2581
Topic starter  

@tfmccarthy 

Once we have a few rounds of freeBasic behind us, we'll talk about upgrading to C++ if you're still interested.

Keep in mind i don't use advanced techniques when coding in c++. No doubt you would do things like create a blob class with a bunch of blob processing methods? 

I have a lot of FreeBASIC code already working although I can translate to C++ given time.

Yesterday I decided to dabble in some console based c++ code to see how much I remembered.

In the example below they are 40x40 pixel images with 4 possible colors saved as values 0,1,2, or 3.

I can't display them as colors on the terminal output so have just used four characters.

In practice the processing part and displaying part would be as a functions to which arrays (images) are passed and an image or description returned.

If anyone wants to run it they can use a free online c++ compiler which provides a console output.

 

#include <iostream>
using namespace std;

int main() {
    // Initialize a 2D array with 40 rows and 40 columns
    int image1[40][40] = {

        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,1,1,1,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,1,1,1,1,1,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0,0},
        {0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0},
        {0,0,0,1,1,1,1,1,1,1,1,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0},
        {0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0},
        {0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
        {0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    };
    
    
    // Initialize a 2D array with 40 rows and 40 columns
    int image2[40][40] = {

        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
        {0,0,0,0,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0,0,0,0,0,0,0,0},      
    };
    

    // Print the 2D image1
    cout << "The 2D image1 is:\n";
    for (int i = 0; i < 40; ++i) {
        for (int j = 0; j < 40; ++j) {
            if (image1[i][j] == 0) {
                cout << "  ";
            } else if (image1[i][j] == 1) {
                cout << "# ";
            } else if (image1[i][j] == 2) {
                cout << "@ ";
            } else {
                cout << ". ";
            }
        }
        cout << endl; // New line for each row
    }
    
    // process image1 to image2
    for (int i = 0; i < 40; ++i) {
        for (int j = 0; j < 40; ++j) {
        	
            if (image1[i][j] == 0) {
                image2[i][j] = 3;
            }
            
            if (image1[i][j] == 1) {
                image2[i][j] = 2;
            }
            
            if (image1[i][j] == 2) {
                image2[i][j] = 0;
            }
            
            if (image1[i][j] == 3){
                image2[i][j] = 1;
            }
        }
    }

    // Print the 2D image2
    cout << "The 2D image2 is:\n";
    for (int i = 0; i < 40; ++i) {
        for (int j = 0; j < 40; ++j) {
        	
            if (image2[i][j] == 0) {
                cout << "  ";
            } else if (image2[i][j] == 1) {
                cout << "# ";
            } else if (image2[i][j] == 2) {
                cout << "@ ";
            } else if (image2[i][j] == 3){
                cout << ". ";
            }
            
        }
    cout << endl; // New line for each row
    }
    
    return 0;
}

 



   
ReplyQuote
TFMcCarthy
(@tfmccarthy)
Member
Joined: 2 years ago
Posts: 518
 

@robotbuilder 

That's ASCII Art. Lot of history behind that. A lot of programs as well.


The one who has the most fun, wins!


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 7 years ago
Posts: 2581
Topic starter  

@tfmccarthy 

Just one last demo example using text display of a binary image using c++.  The code steps around the perimeter of a blob and computes its area (count the @'s) and the length of the perimeter.

 

#include <iostream>
using namespace std;

/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
	
	
const int pCOL = 18;
const int pROW = 18;

// this holds a 18x18 binary image

int image1[pCOL][pROW] = {
    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,1,1,1,1,1,1,0,0,0,0,0,0},
    {0,0,0,0,1,1,1,1,1,1,1,1,1,1,0,0,0,0},
    {0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0},
    {0,0,1,1,1,1,1,1,0,0,0,0,1,1,0,0,0,0},
    {0,0,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0,0},
    {0,0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0,0},
    {0,0,0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0},
    {0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0},
    {0,0,0,0,0,0,1,1,1,1,1,1,1,1,1,0,0,0},
    {0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0},
    {0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,0,0,0},
    {0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0,0},
    {0,0,0,1,1,1,1,1,1,1,1,1,1,1,0,0,0,0},
    {0,0,0,1,1,1,1,1,1,1,1,1,0,0,0,0,0,0},
    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};

int image2[pCOL][pROW] = {
    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
    {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}};


int direction = 0;


// screenres 1280,600,32


//  ** NOTE PIXEL ARRAY MUST HAVE ZERO BORDER VALUES **

// SET TO START POSITION IN PIXEL ARRAY FIRST TOP/LEFT PIXEL OF BLOB
int x = 5;   // current x position
int y = 2;   // current y position

int ox = x;  // old x value
int oy = y;  // olx y value 
int sx = x;  // start x coord
int sy = y;  // start y coord

int xMin = 20;
int yMin = 20;
int xMax = 0;
int yMax = 0;

int AREA = 0;

int perimeter = 0;


do{
    if (x>xMax)
        xMax = x;
        
    if (x<xMin)
        xMin = x;
        
    if (y>yMax)
        yMax = y;
    
    if (y<yMin)
        yMin = y;
    
    perimeter = perimeter + 1;

    image2[x][y]=1;

        
    switch (direction) {

    // EAST -->
    
    case 0:
        if (image1[x+1][y-1] == 1){
            direction = 3; //north
        }else{
            if (image1[x+1][y] == 0){
                direction = 1; //south
            }
        }
        x = x + 1;
        break;
  
    // SOUTH  
    case 1:
        if (image1[x][y+1] == 1){
            direction = 0; //east
        }else{
            if (image1[x-1][y+1] == 0){
                direction = 2; //west
            }
        }
        y = y + 1;
        break;

    // WEST <---
    case 2:
        if (image1[x-2][y] == 1) {
            direction = 1; //south
        }else{
            if (image1[x-2][y-1] == 0) {
                direction = 3; //north
            }
        }

    x = x - 1;
    break;

    // NORTH
    case 3:
        if (image1[x-1][y-2] == 1){
            direction = 2; // west
        }else{
            if (image1[x][y-2] == 0) {
                direction = 0; //east
        }
    }
    
    y = y - 1;
    break;
    
    }



    // compute enclosed area of outline
    AREA = AREA + (x * (y-oy))-(y * (x-ox));

    ox = x;
    oy = y;
 }
while (sx != x || sy != y);
 

for (int j = 0; j<pCOL; j++){
    for (int i = 0; i<pROW; i++){
        if (image1[i][j] == 1) {
            cout << "@ ";
        }else{
            cout << ". ";
        }
    }
    cout << endl;
}

cout << endl << endl;

for (int j = 0; j < pCOL; j++){
    for (int i = 0; i< pROW-1;i++){
        if (image2[i][j] == 1) {
            cout << "# ";
        }else{
            cout << ". ";
        }
    }
    cout << endl;
}

cout << endl << endl;
cout << "AREA =" << AREA/2 << endl;
cout << "perimeter =" << perimeter << endl << endl;

	
	return 0;
}

 



   
ReplyQuote
TFMcCarthy
(@tfmccarthy)
Member
Joined: 2 years ago
Posts: 518
 

@robotbuilder 

When I run this, the output is

. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . @ @ @ . . . . . . . . . .
. . . . @ @ @ @ @ . . . . @ @ @ . .
. . . @ @ @ @ @ @ @ . . . @ @ @ . .
. . . @ @ @ @ @ @ @ . . . @ @ @ . .
. . @ @ @ @ . @ @ @ @ . . @ @ @ . .
. . @ @ @ @ . . @ @ @ . . @ @ @ . .
. . @ @ @ . . . @ @ @ . . @ @ @ . .
. . @ @ @ . . . @ @ @ . . @ @ @ . .
. . @ @ @ . . . @ @ @ . . @ @ @ . .
. . @ @ @ . . . . @ @ @ @ @ @ @ . .
. . . @ @ @ . . . @ @ @ @ @ @ . . .
. . . @ @ @ . . . . @ @ @ @ @ . . .
. . . . . . . . . . @ @ @ @ . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . . .


. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .
. . . . . # # # # . . . . . . . .
. . . . # # . . # # . . . # # # #
. . . # # . . . . # # . . # . . #
. . . # . . . . . . # . . # . . #
. . # # . . # # . . # # . # . . #
. . # . . . # # # . . # . # . . #
. . # . . # # . # . . # . # . . #
. . # . . # . . # . . # . # . . #
. . # . . # . . # . . # . # . . #
. . # . . # . . # # . # # # . . #
. . # # . # # . . # . . . . . # #
. . . # . . # . . # # . . . . # .
. . . # # # # . . . # . . . # # .
. . . . . . . . . . # # # # # . .
. . . . . . . . . . . . . . . . .
. . . . . . . . . . . . . . . . .


AREA =110
perimeter =88

How confident are you about these results?

I didn't look at the code or do a detailed measurement but the numbers seem off. Assuming the perimeter is included in the area, the interior of the shape has 22 pixels, and, at a glance, I count more than that.


The one who has the most fun, wins!


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 7 years ago
Posts: 2581
Topic starter  

@tfmccarthy 

Not sure where you get your 22 from? The area is 110 @'s and the perimeter is 88 #'s.

The outline is of course between pixels but you can't show that using pixels.

The FreeBASIC example below uses a large pixel display and you can watch the perimeter being drawn as you tap a key and this is the final graphic output.

outlined

 

const pCOL = 18
const pROW = 15

dim as integer p(pCOL ,pROW) 'this holds a 18x18 binary image

dim as integer x,y,ox,oy,sx,sy

dim as integer outlineLength

dim shared as integer mag
dim as string ds(4)
ds(0)="EAST ->"
ds(1)="SOUTH V"
ds(2)="WEST <-"
ds(3)="NORTH ^"
dim as integer v,direction
direction = 0

dim as integer AREA
dim as integer xMin,xMax,yMin,yMax  'to box tranversed blob


screen 18

mag = 16

'DISPLAY PIXEL ARRAY IN p(x,y)
for y as integer = 0 to pROW-1
    for x as integer = 0 to pCOL-1
        read v
        p(x,y) = v
        if v = 1 then v = 15
        'draw magnified pixels
        line (x*mag,y*mag)-(x*mag+mag-2,y*mag+mag-2),v,bf
    next x
next y

line (0,0)-(319,239),15,b  'border top/left quadrant of screen display

' ** NOTE PIXEL ARRAY MUST HAVE ZERO BORDER VALUES **

'SET TO START POSITION IN PIXEL ARRAY FIRST TOP/LEFT PIXEL OF BLOB
x = 4   'current x position
y = 1   'current y position
ox = x  'old x value
oy = y  'olx y value
sx = x  'start x coord
sy = y  'start y coord
xMin = 640
yMin = 480
xMax = 0
yMax = 0

AREA = 0

outlineLength = 0


do
    if x>xMax then xMax = x
    if x<xMin then xMin = x
    if y>yMax then yMax = y
    if y<yMin then yMin = y
    
    outlineLength = outlineLength + 1
    
    locate 17,1
    print ds(direction);x;y;"             "
    print "TAP ESC KEY TO TRAVERSE BLOB"

    'draw circle at current x,y position
    if p(x,y)=1 then
        circle (ox*mag+mag/2,oy*mag+mag/2),3,0
    else
        circle (ox*mag+mag/2,oy*mag+mag/2),3,15
    end if
    
    
    select case as const direction

    'EAST -->
    case 0
        if p(x+1,y-1)=1 then
            direction = 3 'north
        else
            if p(x+1,y)=0 then
                direction = 1 'south
            end if
        end if
    x = x + 1
  
    'SOUTH  
    case 1
        if p(x,y+1)=1 then
            direction = 0 'east
        else
            if p(x-1,y+1)=0 then
                direction = 2 'west
            end if
        end if
     y = y + 1

    'WEST <---
    case 2
        if p(x-2,y)=1 then
            direction = 1 'south
        else
            if p(x-2,y-1)=0 then
                direction = 3 'north
        end if
    end if
    x = x - 1

    'NORTH
    case 3
        if p(x-1,y-2)=1 then
            direction = 2 'west
        else
            if p(x,y-2)=0 then
                direction = 0 'east
        end if
    end if
    
    y = y - 1
    
    end select

    'draw magnified outline from point to point
    line (ox*mag+mag/2,oy*mag+mag/2)-(x*mag+mag/2,y*mag+mag/2),9  'BLUE LINES
    line (ox*mag+mag/2+320,oy*mag+mag/2)-(x*mag+mag/2+320,y*mag+mag/2),15

    'compute enclosed area of outline
    AREA = AREA + (x * (y-oy))-(y * (x-ox))

    ox = x
    oy = y
    sleep  'tap key to keep going or comment out for fast traversal
 
loop until sx = x and sy = y

'box blob
line (xMin*mag,yMin*mag)-(xMax*mag,yMax*mag),2,b

locate 20,1   
print "AREA =";AREA/2;"   "
print "outline length =";outlineLength

bsave "outline.bmp",0

sleep

end


'demo 18x18 image.

data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,1,1,1,1,0,0,0,0,1,0,0,0,0,0
data 0,1,1,1,1,0,0,0,1,0,0,1,0,0,0,0,0,0
data 0,0,0,0,1,0,0,0,0,1,1,0,0,0,0,0,0,0
data 0,0,0,0,1,1,0,0,0,0,0,0,0,0,0,0,0,0
data 0,0,0,0,1,0,1,0,0,0,0,0,0,0,0,0,0,0
data 0,0,1,0,1,0,0,0,0,1,1,1,0,0,0,0,0,0
data 0,0,0,1,1,0,0,0,0,1,1,1,0,0,0,1,1,0
data 0,0,0,0,1,0,0,0,0,1,1,1,0,0,0,1,0,0
data 0,0,0,0,1,1,1,1,1,1,1,1,1,1,1,1,0,0
data 0,0,0,1,1,0,0,0,0,1,1,1,1,0,0,0,0,0
data 0,0,1,0,1,0,0,0,0,1,1,1,1,0,0,0,0,0
data 0,0,0,0,1,1,1,0,0,0,0,1,1,0,0,0,0,0
data 0,0,0,0,1,0,1,0,0,0,0,0,1,0,0,0,0,0
data 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
 

 

The blobs dont have to be one color as shown in this image.  They indeed may be made up of textures or other things. The problem is to return the shape and as shown in the image below they might overlap. So the AI needs to return this description. A 5 pointed yellow star, a brown circle (disc), a blue right pointing arrow, on top of a red pentagon. Before the use of CNNs to recognize objects in a scene some objects like high contrast signs or text on paper could be converted to a collections of blobs. Your robot car needs to be able to read traffic signs as well as see the road and avoid obstacles like other cars, people and so on ...

shapes2

 

 



   
ReplyQuote
TFMcCarthy
(@tfmccarthy)
Member
Joined: 2 years ago
Posts: 518
 

@robotbuilder 

Posted by: @robotbuilder
↑

Not sure where you get your 22 from?

Subtractive geometry.

Argh! You're diverting me again!

I'm checking the compiler against every example in the programmer's Guide. This is where I am:

  • Getting Started
  • Source Files
  • Lexical Conventions
  • Variables and Datatypes
  • Arrays
  • Pointers
  • References
  • Declarations
  • User Defined Types
  • Statements and Expressions
  • Procedures
  • Graphics
  • Multi-Threading
  • Making Binaries
  • Preprocessor
  • Other Topics
  • Technical Articles (optional)

I need to focus on this first.


The one who has the most fun, wins!


   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 7 years ago
Posts: 2581
Topic starter  

@tfmccarthy 

My goodness I must confess I never spent time stepping through a manual. I just learned what was required with each tutorial program example and referenced the manuals only as needed. With a new language like Python it was just a case of learning how they did the same thing that I could already do in other languages.



   
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 7 years ago
Posts: 2581
Topic starter  

@tfmccarthy 

I just noticed you actually wrote you were "checking the compiler" with the manual examples not "learning the language" by reading the manual, sorry.

I was suprised that you took on having a go at FreeBASIC so if you aren't enjoying it then I understand.

If the c++ is kept as simple as my FreeBASIC code I would have no trouble using c++.  The big problem was installing SDL on code blocks or some simple editor that itself didn't require a steep learning curve by me to use.

As I age I have found it harder to muster the mental energy when learning new things but still enjoy "solving problems".

Ultimately it is about the algorithm not the language being used to implement it.

One thing about Python is I never had install issues.

pip install opencv-python

If only it was that easy with c++

 

 

 

 



   
ReplyQuote
TFMcCarthy
(@tfmccarthy)
Member
Joined: 2 years ago
Posts: 518
 

@robotbuilder 

This reply risks me being accused of boasting or condescension and I'm sorry about that. It's also a long post with anecdotes and I'm sorry about that as well. I'm just trying to convey my perspective and approach.

I just noticed you actually wrote you were "checking the compiler" with the manual examples not "learning the language" by reading the manual, sorry.

Right, but I'm also "learning the language" (well, this dialect of it.) First, if I'm going to use the language compiler to communicate with you (and other members) then I need to have confidence in the compiler operation. I want to know (not just trust) that the compiler accepts all of the language. The obvious source of all the language statements is the Programmer Guide, which has examples of the statements. Running them through the compiler will uncover any oddities. Along the way, I'll gain experience in making freeBASIC projects and learn how to put one together easily. I'll most likely encounter some compiler error messages, which I need to understand and get comfortable with.

Now, BASIC is a ubiquitous language and freeBASIC is like 3rd or 4th dialect of BASIC I've encountered over the years. BASIC is probably the first programming language people learn. By going through the Programmer's Guide examples, I'll pick up the language dialect.

So, I'm "getting 2 birds with one stone."

That said, I've read enough of the Guide to say that freeBASIC is about as far from standard BASIC as you can get and still claim to be BASIC. It's remarkable, really. It falls somewhere between C and C++; closer to C++, I think. That means it's also akin to Python. So, for our purposes (see below), it's heading in the right direction.

I was suprised that you took on having a go at FreeBASIC so if you aren't enjoying it then I understand.

The response to this is, "Because I'm a Software Engineer." I'm also an Electrical Engineer. Engineer's have a creed. I try to follow it as best I can. Beyond that, I've very fortunate in that my profession and my hobby overlap. I spent 40 years writing software for a living but also, I've spent 40 years reading and writing software for fun (because the one who has the most fun, wins!) For me, software is "playtime", and I love to play. Of course, not all software is fun, but a whole bunch of it is.

For our purposes, ...

... you want to explore what it means to build an autonomous robot. Ambitious. I can go along with that.

... you have a robot that you want to be able to navigate using vision. I find that interesting and have not explored in any depth.

... you don't have a great deal of programming experience and have difficulty making the transition from a language you're comfortable with to a more traditional language used in robotics. I can help you build that bridge.

So, I'm learning freeBASIC and then I'll try to show you that it's not that far from C, C++, or Python.

If the c++ is kept as simple as my FreeBASIC code I would have no trouble using c++.

It's actually the reverse. freeBASIC is closer to C++ than it is to standard BASIC. I hope to demonstrate that to you. I think you'll be pleasantly surprised. Don't get me wrong. C++ is both simple (as simple as C) and complex. It's a hybrid language. The complexity depends on what your need is.

The big problem was installing SDL on code blocks or some simple editor that itself didn't require a steep learning curve by me to use.

(You might want to sit down for this as I'm about to shock your mental model on programming languages.)

With respect to C++, this is a common complaint and misconception. C++ has never claimed to provide a graphic library or an I/O library of any kind. The same is true for C ... and freeBASIC ... and (unless I'm mistaken) Python.. (@byron, are you still following this? Do I speak truth or do I lie?) Nor does the language claim compatibility with code blocks or any other IDE. There's no editor!

There have been a number of attempts to define a "standard" graphics library. The only standard I'm aware of is PHIGS and that was a long time ago and unsuccessful. (I actually have an implementation of PHIGS but have never gotten it running. Maybe I will here.) There's OpenGL, SDL, Allegro, DirectX, et al. A few years ago, Herb Sutter proposed a standard graphics library for C++ and there's an implementation of it somewhere but, to my knowledge, it went nowhere. Pity.

The point is, don't blame the language for poor tools support. You only need an editor, any editor, that will produce an ASCII file; you need a compiler and the associated standard library, and the linker. In the old days, that's all we had. emacs was the popular editor; Whitesmith had the cutting-edge compiler; Phoenix had a cool linker. And Microsoft had a debugger. Before IDE's came around, it was "best of breed"-land.

Graphics libraries are notoriously complex to install. One of the things I will be showing here are the freeBASIC graphics, which are throwbacks to the '80's and '90's days of graphic screen modes.

For our purpose, freeBASIC has support for both SDL and OpenGL but the library version may be out of date. I'll demonstrate them with C++ and the escapi library and then ...

.. we can talk about the problems getting a decent C++ or Python programming environment. This is another one of my pet peeves, however. The pitch is often, "It's easy. Just run this command and Bob's your uncle!"

IMHO, that's snakeoil.

Traditionally, setting up a programming environment is complex. Simply running an unknown install script is dangerous. They've gotten much better over the years, but there's always some problems. See "Fix Pip not working for Python!" I often wonder what the user system looks like after one these commands are run. Are the users even aware of what's going on? Anyway, the installation process complexity can be overcome but again isn't a language issue.

In terms of editor complexity, I confess that even though thousands of users of the vi editor use it without issue, I can't make head nor tails of it. And without an editor, I'm lost. It's embarrassing. I've forgotten which editor I used in the old DOS days.

As I age I have found it harder to muster the mental energy when learning new things but still enjoy "solving problems".

Well, my hope is to help get past the learning curve issue and allow you to easily explore the algorithms that you can use on your robot. The measure is the amount of fun we can squeeze out that.

Well,  looky here, I've fallen behind again. But this was fun.


The one who has the most fun, wins!


   
Lee G reacted
ReplyQuote
robotBuilder
(@robotbuilder)
Member
Joined: 7 years ago
Posts: 2581
Topic starter  

@tfmccarthy 

FreeBASIC started out as a QBASIC replacement but in the hands of developers turned into something much more powerful with C like capabilities.

I guess for me it is also "playtime" at an amateur level. You can enjoy something even if you aren't all that good at it compared with a professional.

I understand the separation of a library or an IDE from the core language itself.  I used the console (terminal?) to compile and run assembler code (NASM and a few others) and I think I remember doing likewise with simple Java examples written with a text editor but I just like the ease of using an IDE.

The experts on the FreeBASIC forum have made it easy for people with my level of understanding to use various libraries however with graphic displays I have found the FreeBASIC graphic library more than sufficient for my needs. It was also the experts that provided the code to use things like the escapi.dll or the K8055.dll without whom I wouldn't still be using FreeBASIC,  I would have persevered with using C++.

The experts also showed me how to interface to the Arduino board via the usb port using FreeBASIC. And then how to install FreeBASIC on the RPi to turn on lights and read buttons.

However I feel that sharing anything here requires using mostly Python code and perhaps C++ code.

There is a version of BASIC for the pico but it is an interpreter not a compiler.

https://geoffg.net/picomite.html

 



   
Lee G reacted
ReplyQuote
byron
(@byron)
No Title
Joined: 7 years ago
Posts: 1283
 

@tfmccarthy "The same is true for C ... and freeBASIC ... and (unless I'm mistaken) Python.. (@byron, are you still following this? Do I speak truth or do I lie?)"

Well you woke me up 😀 

The core python language is similar to C or Basic tis true, but, and its a big but, is that the python 'package' is never implemented as just the core language it always come with its list of standard modules that will be found in all standard python installations.   Augmenting the standard modules  there is also a large number of modules that can be loaded and expected to work on all platforms as well  So the tkinter GUI module is a standard module, whereas the pygame module is not, but its expected that it will be available to install this module on all platforms.  Learning to use the python standard modules is very much part and parcel of learning to use Python and a lot of very useful modules there are too.  I was going to show a list of the modules in a standard python implementation, and they can be found by typing help('module') at the Python REPL, but doing this on my mac gives a list longer than a @robotbuilder program dump, so I thought better of it. 😎   But you normally think of programming things in Python by importing one of the standard module like tkinter to produce the sort of GUI output as per the screen dump below I've just been working on. 

image

But I should note that Micropython, a version of Python designed to work on microcontrollers, has a very much curtailed list of standard modules does not feature a GUI module.

@robotbuilder - I see you remark that you were utilising Python to share code with the likes of 'byron'  and for the Python programs relating to vision.  I do thank you very much for going to the trouble but, whilst my tinkering over the last few years has been in Python and Micropython I retain the ability to code in C, C++ and Basic, and reading your examples in those languages is OK for me.

I did have a brief foray with C doing some minor programming in C back in the 70's  but I spent a larger chunk of time, about 2 years,  later in the 90's  when I earned  my crust contracting using Visual Basic 6 and SQL Server before go in to other stuff.   

When I retired and got a Raspberry Pi my first thoughts was to find a Basic Language to use rather than Python and I found one called Fuze Basic.  That was a good starting point as it has libraries to enable the rpi's GPIO pins to be used.   But I decided to give Python a try, and found it to be right up my street.    At that time I also go an Arduino and re-learnt C and though I would learn some C++.   But Python was good enough for the rpi and the sort of code I was writing for the Arduino to read sensors and that sort of stuff only really needed a 'C' style of programming in the Arduino IDE and my C++ forays ended up  being just a textbook learning exercise for me and I've not used it since then.  But I can still work my was through the code if necessary. 

@robotbuilder I've just looked at your "Just one last demo example using text display of a binary image using c++.  The code steps around the perimeter of a blob and computes its area (count the @'s) and the length of the perimeter"   and in @tfmccarthy output dump a rouge couple of extraneous '#' in the perimeter output hits the eye.  You next puzzle to solve is to remove them or I may be challenged to do it in Python... , or should I try to brush up on C++. mmm 🤔 



   
ReplyQuote
Page 1 / 2