Znaleziono 8 wyników

autor: pltmaxnc
02 sty 2007, 23:22
Forum: Ogólne Dyskusje na Temat Systemów Sterowania CNC
Temat: program ?
Odpowiedzi: 26
Odsłony: 9010

A co z laserem, czy takie zabawkowe wskaźniki mają soczewkę do tworzenia "paska", czy trzeba szukać czegoś lepszego? (czytnik kodów paskowych?)
Myślę że to nie musi być laser tylko jakieś żródlo światla które da czytelny obraz prążka (cienia) na obiekcie.
http://www.vision.caltech.edu/bouguetj/ ... index.html w tym przykladzie jako żródlo slużyla lampa biurkowa a olówek rzucal cień.
Jednak prążek laserowy jest latwiej wyodrębnić z bitmapy.
autor: pltmaxnc
29 gru 2006, 17:49
Forum: Ogólne Dyskusje na Temat Systemów Sterowania CNC
Temat: program ?
Odpowiedzi: 26
Odsłony: 9010

SUPER!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
.....................................chętnie spróbuję , bardzo proszę o przeslanie na priva.
autor: pltmaxnc
23 gru 2006, 23:24
Forum: Ogólne Dyskusje na Temat Systemów Sterowania CNC
Temat: program ?
Odpowiedzi: 26
Odsłony: 9010

No jesteśmy w domu.
W AC3D można plik trasformować na inny format 3D a jest tego duży wybór.
autor: pltmaxnc
22 gru 2006, 22:50
Forum: Ogólne Dyskusje na Temat Systemów Sterowania CNC
Temat: program ?
Odpowiedzi: 26
Odsłony: 9010

Bardzo ciekawe - dzięki.
Cala skarbnica jest tutaj http://www.simple3d.com/
A to specjalnie dla X http://www.muellerr.ch/engineering/scanner/
autor: pltmaxnc
22 gru 2006, 21:15
Forum: Ogólne Dyskusje na Temat Systemów Sterowania CNC
Temat: program ?
Odpowiedzi: 26
Odsłony: 9010

Teraz wiem o co chodzi. Jak zmontuję skaner to poproszę o kompilację i ................ będę znal już chyba wszystkie parametry.
Dlaczego chcesz budować skaner dotykowy ? To jest co prawda pożyteczne urządzenie ale ma sporo poważnych wad. Może jednak optyczny, niekoniecznie z laserem , zobacz jakie to proste .
http://www.vision.caltech.edu/bouguetj/ ... index.html
Ja używam dotykowego opartego na indukcyjnym mierniku przemieszczeń. Prowadzę go tylko w x i y , ruch pionowy czujnika wymusza powierzchnia skanowana. Dzięki temu jest dość szybki ok 5 odczytów/sek przy siatce punktów 0.2 - 0.3 mm , co daje ok 500000 pomiarów na dobę. Pisalem o tym kiedyś na forum można znaleść.
autor: pltmaxnc
21 gru 2006, 23:44
Forum: Ogólne Dyskusje na Temat Systemów Sterowania CNC
Temat: program ?
Odpowiedzi: 26
Odsłony: 9010

Bardzo dziękuję wszystkim za zainteresowanie i rady.
Jest to program do odróbki kolejnych klatek filmu na których jest obracający się model oświetlony promieniem lasera.
Przymierzam sie do zbudowania skanera 3D i przeglądam wszystkie dostępne materialy.
Nie wiem jeszcze jak ten program dziala i czy będzie z niego jakiś pożytek.
Program pochodzi oczywiście ze strony http://www.sjbaker.org/projects/scanner/ , jak slusznie zauważyl Markcomp77.
Prosilbym kogoś o podeslanie wersji skompilowanej bo nie bardzo wiem jak w tym temacie się poruszać.
autor: pltmaxnc
21 gru 2006, 14:39
Forum: Ogólne Dyskusje na Temat Systemów Sterowania CNC
Temat: program ?
Odpowiedzi: 26
Odsłony: 9010

calość
******************************
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include <string.h>

extern "C"
{
#include <jpeglib.h>
#include <jerror.h>
}

#include <math.h>

/*================================================================*/
/* USER EDITABLE SECTION: Change these to suit your scanner */
/*================================================================*/
#define CAMERA_HFOV 50.0f /* Degrees */
#define CAMERA_VFOV (CAMERA_HFOV*4.0f/5.0f) /* Degrees */
#define CAMERA_DISTANCE 0.30f /* Meters */
#define LASER_OFFSET 15.0f /* Degrees */

#define HORIZ_AVG 10 /* Num horizontal points to average */
#define VERT_AVG 10 /* Num vertical points to average */
/*================================================================*/

#define FRAME_SKIP 1 /* Use every n'th frame for speed */
#define POINT_SKIP 1 /* Use every n'th scanline for speed*/
#define RADIANS_TO_DEGREES (180.0f / 3.14159f )
#define DEGREES_TO_RADIANS (3.14159f / 180.0f )

class Image
{
protected:
int width ;
int height ;
unsigned char *buffer ;

public:

Image ( int w, int h )
{
width = w ;
height = h ;
buffer = new unsigned char [ w * h * 3 ] ;
}


Image ()
{
width = height = 0 ;
buffer = NULL ;
}


virtual ~Image () ;

int getWidth () { return width ; }
int getHeight () { return height ; }

unsigned char *getPixels () { return buffer ; }

unsigned int getPixelArea ( float x1, float y1,
float x2, float y2,
unsigned int keyColour ) ;

unsigned char getPixelRed ( int x, int y )
{
return (unsigned int) buffer [ ( y * width + x ) * 3 + 0 ] ;
}

unsigned char getPixelGreen ( int x, int y )
{
return (unsigned int) buffer [ ( y * width + x ) * 3 + 1 ] ;
}

unsigned char getPixelBlue ( int x, int y )
{
return (unsigned int) buffer [ ( y * width + x ) * 3 + 2 ] ;
}

unsigned int getPixel ( float x, float y )
{
return getPixel ( (int) x, (int) y ) ;
}

unsigned int getPixel ( int x, int y )
{
int p = ( y * width + x ) * 3 ;

return ( (unsigned int) buffer [ p + 0 ] << 24 ) +
( (unsigned int) buffer [ p + 1 ] << 16 ) +
( (unsigned int) buffer [ p + 2 ] << 8 ) + 255 ;
}

void setPixel ( float x, float y, unsigned int rgba )
{
setPixel ( (int) x, (int) y, rgba ) ;
}

void setPixel ( int x, int y, unsigned int rgba )
{
int p = ( y * width + x ) * 3 ;

if ( ( rgba & 0xFF ) == 0 )
return ;

if ( ( rgba & 0xFF ) == 255 )
{
buffer [ p + 0 ] = ( rgba >> 24 ) & 0xFF ;
buffer [ p + 1 ] = ( rgba >> 16 ) & 0xFF ;
buffer [ p + 2 ] = ( rgba >> 8 ) & 0xFF ;
}
else
{
unsigned int r = ( rgba >> 24 ) & 0xFF ;
unsigned int g = ( rgba >> 16 ) & 0xFF ;
unsigned int b = ( rgba >> 8 ) & 0xFF ;
unsigned int a = ( rgba >> 0 ) & 0xFF ;
unsigned int ac = 255 - a ;

buffer [ p + 0 ] = (unsigned char)((int)(buffer [ p + 0 ]) * ac / 255 + r * a / 255 ) ;
buffer [ p + 1 ] = (unsigned char)((int)(buffer [ p + 1 ]) * ac / 255 + g * a / 255 ) ;
buffer [ p + 2 ] = (unsigned char)((int)(buffer [ p + 2 ]) * ac / 255 + b * a / 255 ) ;
}
}

virtual int load ( char *fname ) = NULL ;

} ;



class JPEG : public Image
{
public:

JPEG () : Image () {}
JPEG ( int w, int h ) : Image ( w, h ) {}

virtual int load ( char *fname ) ;
} ;

static const int _endianTest = 1;
#define isLittleEndian (*((char *) &_endianTest ) != 0)
#define isBigEndian (*((char *) &_endianTest ) == 0)

Image::~Image ()
{
delete buffer ;
}


int JPEG::load ( char * filename )
{
jpeg_decompress_struct cinfo ;
jpeg_error_mgr jerr ;

FILE *fd ;
JSAMPARRAY linebuffer ;
int row_stride ;

if ( ( fd = fopen ( filename, "rb" ) ) == NULL )
{
perror ( "readJPEG" ) ;
fprintf ( stderr, "readJPEG: Can't open %s for reading\n", filename ) ;
return 0 ;
}


cinfo.err = jpeg_std_error ( &jerr ) ;
jpeg_create_decompress ( &cinfo ) ;
jpeg_stdio_src ( &cinfo, fd ) ;
jpeg_read_header ( &cinfo, TRUE ) ;
jpeg_start_decompress ( &cinfo ) ;

row_stride = cinfo.output_width * cinfo.output_components ;

if ( cinfo.output_components != 3 )
{
fprintf ( stderr, "readJPEG: %s has %d components?!?\n", filename,
cinfo.output_components ) ;
return 0 ;
}

linebuffer = (*cinfo.mem->alloc_sarray)
( (j_common_ptr) &cinfo, JPOOL_IMAGE, row_stride, 1 ) ;

delete buffer ;

height = cinfo.output_height ;
width = cinfo.output_width ;

buffer = new unsigned char [ width * height * 3 ] ;

while (cinfo.output_scanline < cinfo.output_height)
{
int y = cinfo.output_scanline ;

/*
jpeg_read_scanlines expects an array of pointers to scanlines.
Here the array is only one element long, but you could ask for
more than one scanline at a time if that's more convenient.
*/

jpeg_read_scanlines ( &cinfo, linebuffer, 1 ) ;
memcpy ( & buffer [ y * row_stride ], linebuffer[0], row_stride ) ;
}

jpeg_finish_decompress ( &cinfo ) ;
jpeg_destroy_decompress ( &cinfo ) ;

fclose ( fd ) ;
return 1 ;
}


unsigned int Image::getPixelArea ( float x1, float y1,
float x2, float y2,
unsigned int keyColour )
{
if ( x2-x1 <= 0.0f || y2-y1 <= 0.0f )
return 0x00000000 ;

unsigned int r = ( keyColour >> 24 ) & 0xFF ;
unsigned int g = ( keyColour >> 16 ) & 0xFF ;
unsigned int b = ( keyColour >> 8 ) & 0xFF ;

float area_tot = (x2-x1) * (y2-y1) ;

float r_tot = 0.0f ;
float g_tot = 0.0f ;
float b_tot = 0.0f ;

float rgb_area = 0.0f ;

for ( int i = (int)floor(x1) ; i <= (int)ceil(x2) ; i++ )
for ( int j = (int)floor(y1) ; j <= (int)ceil(y2) ; j++ )
{
if ( i < 0 || i >= width ||
j < 0 || j >= height ||
getPixel( i, j ) == keyColour )
continue ;

float xa = ( x1 > (float) i ) ? x1 : (float) i ;
float xb = ( x2 < (float)(i+1)) ? x2 : (float) (i+1) ;
float ya = ( y1 > (float) j ) ? y1 : (float) j ;
float yb = ( y2 < (float)(j+1)) ? y2 : (float) (j+1) ;

if ( xb-xa <= 0.0f || yb-ya <= 0.0f )
continue ;

float area = (xb-xa) * (yb-ya) ;

rgb_area += area ;

r_tot += getPixelRed ( i, j ) * area ;
g_tot += getPixelGreen ( i, j ) * area ;
b_tot += getPixelBlue ( i, j ) * area ;
}

if ( rgb_area <= 0.0f )
return 0x00000000 ;

r_tot /= rgb_area ;
g_tot /= rgb_area ;
b_tot /= rgb_area ;

float a_tot = rgb_area * 255.0f / area_tot ;

if ( r_tot > 255.0f ) r_tot = 255.0f ;
if ( g_tot > 255.0f ) g_tot = 255.0f ;
if ( b_tot > 255.0f ) b_tot = 255.0f ;
if ( a_tot > 255.0f ) a_tot = 255.0f ;

if ( r_tot <= 0.0f ) r_tot = 0.0f ;
if ( g_tot <= 0.0f ) g_tot = 0.0f ;
if ( b_tot <= 0.0f ) b_tot = 0.0f ;
if ( a_tot <= 0.0f ) a_tot = 0.0f ;

return ( (unsigned int) r_tot << 24 ) +
( (unsigned int) g_tot << 16 ) +
( (unsigned int) b_tot << 8 ) +
( (unsigned int) a_tot << 0 ) ;
}


void ASAtoSAS ( float angA, float lenB, float angC,
float *lenA, float *angB, float *lenC )
{
/* Find the missing angle */

float bb = 180.0f - (angA + angC) ;

if ( angB ) *angB = bb ;

/* Convert everything to radians */

angA *= DEGREES_TO_RADIANS ;
angC *= DEGREES_TO_RADIANS ;
bb *= DEGREES_TO_RADIANS ;

/* Use Sine Rule */

float sinB = sin ( bb ) ;

if ( sinB == 0.0f )
{
if ( lenA ) *lenA = lenB / 2.0f ; /* One valid interpretation */
if ( lenC ) *lenC = lenB / 2.0f ;
}
else
{
if ( lenA ) *lenA = lenB * sin(angA) / sinB ;
if ( lenC ) *lenC = lenB * sin(angC) / sinB ;
}
}


float *processRawFrame ( char *fname, int f, int num_frames, int *num_points )
{
JPEG *jpg = new JPEG ;

jpg -> load ( fname ) ;

int np = jpg->getHeight() / POINT_SKIP ;

*num_points = np ;

float *res = new float [ 3 * np ] ;

float frame_angle = ((float) f) * (360.0f / (float) num_frames) ;

for ( int j = 0 ; j < np ; j++ )
{
/* Find the brightest pixel */

float max = 0.0f ;
int maxpos = -1 ;

for ( int i = 0 ; i < jpg -> getWidth () ; i++ )
{
unsigned int px = jpg -> getPixel ( i, j*POINT_SKIP ) ;

float brightness = ((float)(( px >> 24 ) & 0xFF)) / 255.0f +
((float)(( px >> 16 ) & 0xFF)) / 255.0f +
((float)(( px >> 8 ) & 0xFF)) / 255.0f ;

if ( brightness > max )
{
max = brightness ;
maxpos = i ;
}
}

float radius ;
float camera_angle = CAMERA_HFOV *
(0.5f - (float)maxpos / (float)jpg -> getWidth ()) ;

ASAtoSAS ( camera_angle, CAMERA_DISTANCE, LASER_OFFSET,
& radius, NULL, NULL ) ;

float x = radius * sin ( frame_angle * DEGREES_TO_RADIANS ) ;
float y = radius * cos ( frame_angle * DEGREES_TO_RADIANS ) ;
float z = atan ( (CAMERA_VFOV * DEGREES_TO_RADIANS / 2.0f) ) *
2.0f * CAMERA_DISTANCE * (float) j / (float) np ;

// if ( max < 1.50 )
// x = y = 0.0f ;

res [ 3 * j + 0 ] = x ;
res [ 3 * j + 1 ] = y ;
res [ 3 * j + 2 ] = z ;
}

delete jpg ;

return res ;
}


void outputFrames ( int num_points, int num_frames, float **vertices )
{
int num_outframes = num_frames / HORIZ_AVG ;
int num_outpoints = num_points / VERT_AVG ;

printf ( "AC3Db\n" ) ;
printf ( "MATERIAL \"ac3dmat1\" rgb 1 1 1 amb 0.2 0.2 0.2 "
"emis 0 0 0 spec 0.5 0.5 0.5 shi 10 trans 0\n" ) ;
printf ( "OBJECT world\n" ) ;
printf ( "kids 1\n" ) ;

printf ( "OBJECT poly\n" ) ;
printf ( "name \"scan3d\"\n" ) ;
printf ( "loc 0.0 0.0 0.0\n" ) ;
printf ( "numvert %d\n", num_outpoints*num_outframes ) ;

for ( int f = 0 ; f < num_outframes ; f++ )
for ( int i = 0 ; i < num_outpoints ; i++ )
{
float avg [ 3 ] = { 0.0f, 0.0f, 0.0f } ;

for ( int ff = 0 ; ff < HORIZ_AVG ; ff++ )
for ( int ii = 0 ; ii < VERT_AVG ; ii++ )
{
avg [ 0 ] += vertices[f*HORIZ_AVG+ff][(i*VERT_AVG+ii)*3+0] ;
avg [ 1 ] += vertices[f*HORIZ_AVG+ff][(i*VERT_AVG+ii)*3+1] ;
avg [ 2 ] += vertices[f*HORIZ_AVG+ff][(i*VERT_AVG+ii)*3+2] ;
}

avg [ 0 ] /= (float)( HORIZ_AVG*VERT_AVG ) ;
avg [ 1 ] /= (float)( HORIZ_AVG*VERT_AVG ) ;
avg [ 2 ] /= (float)( HORIZ_AVG*VERT_AVG ) ;

printf ( "%f %f %f\n", avg [ 0 ], avg [ 1 ], avg [ 2 ] ) ;
}

printf ( "numsurf %d\n", num_outframes * (num_outpoints-1) * 2 ) ;

for ( int f = 0 ; f < num_outframes ; f++ )
{
int ff = (f==num_outframes-1) ? 0 : f+1 ;

for ( int i = 0 ; i < num_outpoints-1 ; i++ )
{
int ii = i+1 ;

printf ( "SURF 0x10\n" ) ;
printf ( "mat 0\n" ) ;
printf ( "refs 3\n" ) ;
printf ( "%d %f %f\n", ff * num_outpoints + ii,
(float) ff / (float) num_outframes,
(float) ii / (float) num_outpoints ) ;
printf ( "%d %f %f\n", ff * num_outpoints + i,
(float) ff / (float) num_outframes,
(float) i / (float) num_outpoints ) ;
printf ( "%d %f %f\n", f * num_outpoints + i,
(float) f / (float) num_outframes,
(float) i / (float) num_outpoints ) ;

printf ( "SURF 0x10\n" ) ;
printf ( "mat 0\n" ) ;
printf ( "refs 3\n" ) ;
printf ( "%d %f %f\n", f * num_outpoints + ii,
(float) f / (float) num_outframes,
(float) i / (float) num_outpoints ) ;
printf ( "%d %f %f\n", ff * num_outpoints + ii,
(float) ff / (float) num_outframes,
(float) ii / (float) num_outpoints ) ;
printf ( "%d %f %f\n", f * num_outpoints + i,
(float) f / (float) num_outframes,
(float) i / (float) num_outpoints ) ;
}

}
printf ( "kids 0\n" ) ;
}



int main ( int argc, char **argv )
{
float **vertices ;

int num_frames = 0 ;

for ( int i = 0 ; true ; i++ )
{
FILE *tmp ;
char fname [ 100 ] ;

sprintf ( fname, "%08d.jpg", i*FRAME_SKIP ) ;

fprintf ( stderr, "Checking %s\r", fname ) ;

if ( (tmp = fopen ( fname, "r" )) == NULL )
break ;

fclose ( tmp ) ;

num_frames = i+1 ;
}

fprintf ( stderr, "\nProcessing %d frames...\n", num_frames ) ;

vertices = new float * [ num_frames ] ;

int npoints = -1 ;

for ( int i = 0 ; i < num_frames ; i++ )
{
int np ;
char fname [ 100 ] ;
sprintf ( fname, "%08d.jpg", i*FRAME_SKIP ) ;

fprintf ( stderr, "Processing frame %d/%d '%s'\r",
i, num_frames, fname ) ;

vertices [ i ] = processRawFrame ( fname, i, num_frames, &np ) ;

assert ( npoints == -1 || np == npoints ) ;

npoints = np ;
}

fprintf ( stderr, "\nOutputting...\n", num_frames ) ;
outputFrames ( npoints, num_frames, vertices ) ;
}
autor: pltmaxnc
21 gru 2006, 13:00
Forum: Ogólne Dyskusje na Temat Systemów Sterowania CNC
Temat: program ?
Odpowiedzi: 26
Odsłony: 9010

program ?

W jakim środowisku uruchomoć można taki program ?

>>>>>>>>>>>>>>>>>>>>>>>>>>>
ę#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include <string.h>

extern "C"
{
#include <jpeglib.h>
#include <jerror.h>
}

#include <math.h>

/*================================================================*/
/* USER EDITABLE SECTION: Change these to suit your scanner */
/*================================================================*/
#define CAMERA_HFOV 50.0f /* Degrees */
#define CAMERA_VFOV (CAMERA_HFOV*4.0f/5.0f) /* Degrees */
#define CAMERA_DISTANCE 0.30f /* Meters */
#define LASER_OFFSET 15.0f /* Degrees */

#define HORIZ_AVG 10 /* Num horizontal points to average */
#define VERT_AVG 10 /* Num vertical points to average */
/*================================================================*/

#define FRAME_SKIP 1 /* Use every n'th frame for speed */
#define POINT_SKIP 1 /* Use every n'th scanline for speed*/
#define RADIANS_TO_DEGREES (180.0f / 3.14159f )
#define DEGREES_TO_RADIANS (3.14159f / 180.0f )

class Image
{
protected:
int width ;
int height ;
unsigned char *buffer ;

public:

Image ( int w, int h )
{
width = w ;
height = h ;
buffer = new unsigned char [ w * h * 3 ] ;
}


Image ()
{
width = height = 0 ;
buffer = NULL ;
}


virtual ~Image () ;

int getWidth () { return width ; }
int getHeight () { return height ; }

unsigned char *getPixels () { return buffer ; }

unsigned int getPixelArea ( float x1, float y1,
float x2, float y2,
unsigned int keyColour ) ;
itd...............................................................................................
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

Wróć do „program ?”