Bem vindo ao Sabugosa!


Sabugosa é um grupo de entusiastas, hackers, nerds, engenheiros, técnicos, malucos e cia. de São José dos Campos/SP, e região

Num passado recente nosso grupo tinha uma sede, que foi o primeiro hackerspace do Vale do Paraíba.

Hoje, porém, nos reunimos semanalmente em um parque da cidade, para trocar idéias, discutir e trabalhar em projetos comunitários

Como participar

Se voce tem interesse em projetos que envolvam tecnologia (programação, eletrônicos, computadores, artes digitais, etc), apareça num de nossos encontros.

Nos reunimos todos os sábados de manhã no quiosque grande do parque Santos Dumont. É só chegar! :-)

                                                                                                                                                                                                        

       //turns off console messages - default is to print messages        static void setVerbose(bool _verbose);        //Functions in
 rough order they should be used.        static int listDevices(bool silent = false);        //needs to be called after listDevices - 
otherwise returns NULL        static char * getDeviceName(int deviceID);        //choose to use callback based capture - or single thr
eaded        void setUseCallback(bool useCallback);        //call before setupDevice        //directshow will try and get the closest 
possible framerate to what is requested        void setIdealFramerate(int deviceID, int idealFramerate);        //some devices will st
op delivering frames after a while - this method gives you the option to try and reconnect        //to a device if videoInput detects 
that a device has stopped delivering frames.        //you MUST CALL isFrameNew every app loop for this to have any effect        void 
setAutoReconnectOnFreeze(int deviceNumber, bool doReconnect, int numMissedFramesBeforeReconnect);        //Choose one of these five to
 setup your device        bool setupDevice(int deviceID);        bool setupDevice(int deviceID, int w, int h);        bool setupDevice
Fourcc(int deviceID, int w, int h,int fourcc);        //These two are only for capture cards        //USB and Firewire cameras souldn'
t specify connection        bool setupDevice(int deviceID, int connection);        bool setupDevice(int deviceID, int w, int h, int co
nnection);        bool setFourcc(int deviceNumber, int fourcc);        //If you need to you can set your NTSC/PAL/SECAM        //prefe
rence here. if it is available it will be used.        //see #defines above for available formats - eg VI_NTSC_M or VI_PAL_B        //
should be called after setupDevice        //can be called multiple times        bool setFormat(int deviceNumber, int format);        /
/Tells you when a new frame has arrived - you should call this if you have specified setAutoReconnectOnFreeze to true        bool isFr
ameNew(int deviceID);        bool isDeviceSetup(int deviceID);        //Returns the pixels - flipRedAndBlue toggles RGB/BGR flipping -
 and you can flip the image too        unsigned char * getPixels(int deviceID, bool flipRedAndBlue = true, bool flipImage = false);   
     //Or pass in a buffer for getPixels to fill returns true if successful.        bool getPixels(int id, unsigned char * pixels, boo
l flipRedAndBlue = true, bool flipImage = false);        //Launches a pop up settings window        //For some reason in GLUT you have
 to call it twice each time.        void showSettingsWindow(int deviceID);        //Manual control over settings thanks.....        //
These are experimental for now.        bool setVideoSettingFilter(int deviceID, long Property, long lValue, long Flags = 0, bool useDe
faultValue = false);        bool setVideoSettingFilterPct(int deviceID, long Property, float pctValue, long Flags = 0);        bool ge
tVideoSettingFilter(int deviceID, long Property, long &min, long &max, long &SteppingDelta, long &currentValue, long &flags, long &def
aultValue);        bool setVideoSettingCamera(int deviceID, long Property, long lValue, long Flags = 0, bool useDefaultValue = false);
        bool setVideoSettingCameraPct(int deviceID, long Property, float pctValue, long Flags = 0);        bool getVideoSettingCamera(
int deviceID, long Property, long &min, long &max, long &SteppingDelta, long ¤tValue, long &flags, long &defaultValue);        /
/bool setVideoSettingCam(int deviceID, long Property, long lValue, long Flags = NULL, bool useDefaultValue = false);        //get widt
h, height and number of pixels        int  getWidth(int deviceID);        int  getHeight(int deviceID);        int  getSize(int device
ID);        int  getFourcc(int deviceID);        double getFPS(int deviceID);        //completely stops and frees a device        void
 stopDevice(int deviceID);        //as above but then sets it up with same settings        bool restartDevice(int deviceID);        //
number of devices available        int  devicesFound;        // mapping from OpenCV CV_CAP_PROP to videoinput/dshow properties        
int getVideoPropertyFromCV(int cv_property);        int getCameraPropertyFromCV(int cv_property);    private:        void setPhyCon(in
t deviceID, int conn);        void setAttemptCaptureSize(int deviceID, int w, int h,GUID mediaType=MEDIASUBTYPE_RGB24);        bool se
tup(int deviceID);        void processPixels(unsigned char * src, unsigned char * dst, int width, int height, bool bRGB, bool bFlip); 
       int  start(int deviceID, videoDevice * VD);        int  getDeviceCount();        void getMediaSubtypeAsString(GUID type, char *
 typeAsString);        GUID *getMediaSubtypeFromFourcc(int fourcc);        int    getFourccFromMediaSubtype(GUID type);        void ge
tVideoPropertyAsString(int prop, char * propertyAsString);        void getCameraPropertyAsString(int prop, char * propertyAsString);  
      HRESULT getDevice(IBaseFilter **pSrcFilter, int deviceID, WCHAR * wDeviceName, char * nDeviceName);        static HRESULT ShowFi
lterPropertyPages(IBaseFilter *pFilter);        static HRESULT ShowStreamPropertyPages(IAMStreamConfig  *pStream);        HRESULT Save
GraphFile(IGraphBuilder *pGraph, WCHAR *wszPath);        HRESULT routeCrossbar(ICaptureGraphBuilder2 **ppBuild, IBaseFilter **pVidInFi
lter, int conType, GUID captureMode);        //don't touch        static bool comInit();        static bool comUnInit();        int  c
onnection;        int  callbackSetCount;        bool bCallback;        GUID CAPTURE_MODE;        //Extra video subtypes        GUID ME
DIASUBTYPE_Y800;        GUID MEDIASUBTYPE_Y8;        GUID MEDIASUBTYPE_GREY;        videoDevice * VDList[VI_MAX_CAMERAS];        GUID 
mediaSubtypes[VI_NUM_TYPES];        long formatTypes[VI_NUM_FORMATS];        static void __cdecl basicThread(void * objPtr);        st
atic char deviceNames[VI_MAX_CAMERAS][255];};///////////////////////////  HANDY FUNCTIONS  /////////////////////////////static void My
FreeMediaType(AM_MEDIA_TYPE& mt){    if (mt.cbFormat != 0)    {        CoTaskMemFree((PVOID)mt.pbFormat);        mt.cbFormat = 0;     
   mt.pbFormat = NULL;    }    if (mt.pUnk != NULL)    {        // Unecessary because pUnk should not be used, but safest.        mt.p
Unk->Release();        mt.pUnk = NULL;    }}static void MyDeleteMediaType(AM_MEDIA_TYPE *pmt){    if (pmt != NULL)    {        MyFreeM
ediaType(*pmt);        CoTaskMemFree(pmt);    }}//////////////////////////////  CALLBACK  //////////////////////////////////Callback c
lassclass SampleGrabberCallback : public ISampleGrabberCB{public:    //------------------------------------------------    SampleGrabb
erCallback(){        InitializeCriticalSection(&critSection);        freezeCheck = 0;        bufferSetup         = false;        newFr
ame            = false;        latestBufferLength  = 0;        hEvent = CreateEvent(NULL, true, false, NULL);    }    //--------------
----------------------------------    virtual ~SampleGrabberCallback(){        ptrBuffer = NULL;        DeleteCriticalSection(&critSec
tion);        CloseHandle(hEvent);        if(bufferSetup){            delete[] pixels;        }    }    //----------------------------
--------------------    bool setupBuffer(int numBytesIn){        if(bufferSetup){            return false;        }else{            nu
mBytes            = numBytesIn;            pixels              = new unsigned char[numBytes];            bufferSetup         = true;  
          newFrame            = false;            latestBufferLength  = 0;        }        return true;    }    //--------------------
----------------------------    STDMETHODIMP_(ULONG) AddRef() { return 1; }    STDMETHODIMP_(ULONG) Release() { return 2; }    //-----
-------------------------------------------    STDMETHODIMP QueryInterface(REFIID, void **ppvObject){        *ppvObject = static_cast<
ISampleGrabberCB*>(this);        return S_OK;    }    //This method is meant to have less overhead    //------------------------------
------------------    STDMETHODIMP SampleCB(double , IMediaSample *pSample){        if(WaitForSingleObject(hEvent, 0) == WAIT_OBJECT_0
) return S_OK;        HRESULT hr = pSample->GetPointer(&ptrBuffer);        if(hr == S_OK){            latestBufferLength = pSample->Ge
tActualDataLength();              if(latestBufferLength == numBytes){                EnterCriticalSection(&critSection);              
        memcpy(pixels, ptrBuffer, latestBufferLength);                    newFrame    = true;                    freezeCheck = 1;     
           LeaveCriticalSection(&critSection);                SetEvent(hEvent);            }else{                printf("ERROR: Sample
CB() - buffer sizes do not match\n");            }        }        return S_OK;    }    //This method is meant to have more overhead  
  STDMETHODIMP BufferCB(double, BYTE *, long){        return E_NOTIMPL;    }    int freezeCheck;    int latestBufferLength;    int num
Bytes;    bool newFrame;    bool bufferSetup;    unsigned char * pixels;    unsigned char * ptrBuffer;    CRITICAL_SECTION critSection
;    HANDLE hEvent;};//////////////////////////////  VIDEO DEVICE  ////////////////////////////////// --------------------------------
--------------------------------------//    Should this class also be the callback?//// ----------------------------------------------
------------------------videoDevice::videoDevice(){     pCaptureGraph      = NULL;    // Capture graph builder object     pGraph      
       = NULL;    // Graph builder object     pControl           = NULL;    // Media control object     pVideoInputFilter  = NULL; // 
Video Capture filter     pGrabber           = NULL; // Grabs frame     pDestFilter        = NULL; // Null Renderer Filter     pGrabber
F          = NULL; // Grabber Filter     pMediaEvent        = NULL;     streamConf         = NULL;     pAmMediaType       = NULL;     
//This is our callback class that processes the frame.     sgCallback           = new SampleGrabberCallback();     sgCallback->newFram
e = false;     //Default values for capture type     videoType          = MEDIASUBTYPE_RGB24;     connection         = PhysConn_Video_
Composite;     storeConn          = 0;     videoSize          = 0;     width              = 0;     height             = 0;     tryWidt
h           = 640;     tryHeight          = 480;     tryVideoType = MEDIASUBTYPE_RGB24;     nFramesForReconnect= 10000;     nFramesRun
ning     = 0;     myID               = -1;     tryDiffSize        = true;     useCrossbar        = false;     readyToCapture     = fal
se;     sizeSet            = false;     setupStarted       = false;     specificFormat     = false;     autoReconnect      = false;   
  requestedFrameTime = -1;     memset(wDeviceName, 0, sizeof(WCHAR) * 255);     memset(nDeviceName, 0, sizeof(char) * 255);}// -------
---------------------------------------------------------------//    The only place we are doing new//// -----------------------------
-----------------------------------------void videoDevice::setSize(int w, int h){    if(sizeSet){        if(verbose)printf("SETUP: Err
or device size should not be set more than once \n");    }    else    {        width               = w;        height              = h
;        videoSize           = w*h*3;        sizeSet             = true;        pixels              = new unsigned char[videoSize];   
     pBuffer             = new char[videoSize];        memset(pixels, 0 , videoSize);        sgCallback->setupBuffer(videoSize);    }}
// ----------------------------------------------------------------------/       //turns off console messages - default is to print me
ssages        static void setVerbose(bool _verbose);        //Functions in rough order they should be used.        static int listDevi
ces(bool silent = false);        //needs to be called after listDevices - otherwise returns NULL        static char * getDeviceName(in
t deviceID);        //choose to use callback based capture - or single threaded        void setUseCallback(bool useCallback);        /
/call before setupDevice        //directshow will try and get the closest possible framerate to what is requested        void setIdeal
Framerate(int deviceID, int idealFramerate);        //some devices will stop delivering frames after a while - this method gives you t
he option to try and reconnect        //to a device if videoInput detects that a device has stopped delivering frames.        //you MU
ST CALL isFrameNew every app loop for this to have any effect        void setAutoReconnectOnFreeze(int deviceNumber, bool doReconnect,
 int numMissedFramesBeforeReconnect);        //Choose one of these five to setup your device        bool setupDevice(int deviceID);   
     bool setupDevice(int deviceID, int w, int h);        bool setupDeviceFourcc(int deviceID, int w, int h,int fourcc);        //Thes
e two are only for capture cards        //USB and Firewire cameras souldn't specify connection        bool setupDevice(int deviceID, i
nt connection);        bool setupDevice(int deviceID, int w, int h, int connection);        bool setFourcc(int deviceNumber, int fourc
c);        //If you need to you can set your NTSC/PAL/SECAM        //preference here. if it is available it will be used.        //see
 #defines above for available formats - eg VI_NTSC_M or VI_PAL_B        //should be called after setupDevice        //can be called mu
ltiple times        bool setFormat(int deviceNumber, int format);        //Tells you when a new frame has arrived - you should call th
is if you have specified setAutoReconnectOnFreeze to true        bool isFrameNew(int deviceID);        bool isDeviceSetup(int deviceID
);        //Returns the pixels - flipRedAndBlue toggles RGB/BGR flipping - and you can flip the image too        unsigned char * getPi
xels(int deviceID, bool flipRedAndBlue = true, bool flipImage = false);        //Or pass in a buffer for getPixels to fill returns tru
e if successful.        bool getPixels(int id, unsigned char * pixels, bool flipRedAndBlue = true, bool flipImage = false);        //L
aunches a pop up settings window        //For some reason in GLUT you have to call it twice each time.        void showSettingsWindow(
int deviceID);        //Manual control over settings thanks.....        //These are experimental for now.        bool setVideoSettingF
ilter(int deviceID, long Property, long lValue, long Flags = 0, bool useDefaultValue = false);        bool setVideoSettingFilterPct(in
t deviceID, long Property, float pctValue, long Flags = 0);        bool getVideoSettingFilter(int deviceID, long Property, long &min, 
long &max, long &SteppingDelta, long &currentValue, long &flags, long &defaultValue);        bool setVideoSettingCamera(int deviceID, 
long Property, long lValue, long Flags = 0, bool useDefaultValue = false);        bool setVideoSettingCameraPct(int deviceID, long Pro
perty, float pctValue, long Flags = 0);        bool getVideoSettingCamera(int deviceID, long Property, long &min, long &max, long &Ste
ppingDelta, long ¤tValue, long &flags, long &defaultValue);        //bool setVideoSettingCam(int deviceID, long Property, long l
Value, long Flags = NULL, bool useDefaultValue = false);        //get width, height and number of pixels        int  getWidth(int devi
ceID);        int  getHeight(int deviceID);        int  getSize(int deviceID);        int  getFourcc(int deviceID);        double getF
PS(int deviceID);        //completely stops and frees a device        void stopDevice(int deviceID);        //as above but then sets i
t up with same settings        bool restartDevice(int deviceID);        //number of devices available        int  devicesFound;       
 // mapping from OpenCV CV_CAP_PROP to videoinput/dshow properties        int getVideoPropertyFromCV(int cv_property);        int getC
ameraPropertyFromCV(int cv_property);    private:        void setPhyCon(int deviceID, int conn);        void setAttemptCaptureSize(int
 deviceID, int w, int h,GUID mediaType=MEDIASUBTYPE_RGB24);        bool setup(int deviceID);        void processPixels(unsigned char *
 src, unsigned char * dst, int width, int height, bool bRGB, bool bFlip);        int  start(int deviceID, videoDevice * VD);        in
t  getDeviceCount();        void getMediaSubtypeAsString(GUID type, char * typeAsString);        GUID *getMediaSubtypeFromFourcc(int f
ourcc);        int    getFourccFromMediaSubtype(GUID type);        void getVideoPropertyAsString(int prop, char * propertyAsString);  
      void getCameraPropertyAsString(int prop, char * propertyAsString);        HRESULT getDevice(IBaseFilter **pSrcFilter, int device
ID, WCHAR * wDeviceName, char * nDeviceName);        static HRESULT ShowFilterPropertyPages(IBaseFilter *pFilter);        static HRESU
LT ShowStreamPropertyPages(IAMStreamConfig  *pStream);        HRESULT SaveGraphFile(IGraphBuilder *pGraph, WCHAR *wszPath);        HRE
SULT routeCrossbar(ICaptureGraphBuilder2 **ppBuild, IBaseFilter **pVidInFilter, int conType, GUID captureMode);        //don't touch  
      static bool comInit();        static bool comUnInit();        int  connection;        int  callbackSetCount;        bool bCallba
ck;        GUID CAPTURE_MODE;        //Extra video subtypes        GUID MEDIASUBTYPE_Y800;        GUID MEDIASUBTYPE_Y8;        GUID ME
DIASUBTYPE_GREY;        videoDevice * VDList[VI_MAX_CAMERAS];        GUID mediaSubtypes[VI_NUM_TYPES];        long formatTypes[VI_NUM_
FORMATS];        static void __cdecl basicThread(void * objPtr);        static char deviceNames[VI_MAX_CAMERAS][255];};///////////////
////////////  HANDY FUNCTIONS  /////////////////////////////static void MyFreeMediaType(AM_MEDIA_TYPE& mt){    if (mt.cbFormat != 0)  
  {        CoTaskMemFree((PVOID)mt.pbFormat);        mt.cbFormat = 0;        mt.pbFormat = NULL;    }    if (mt.pUnk != NULL)    {    
    // Unecessary because pUnk should not be used, but safest.        mt.pUnk->Release();        mt.pUnk = NULL;    }}static void MyDe
leteMediaType(AM_MEDIA_TYPE *pmt){    if (pmt != NULL)    {        MyFreeMediaType(*pmt);        CoTaskMemFree(pmt);    }}////////////
//////////////////  CALLBACK  //////////////////////////////////Callback classclass SampleGrabberCallback : public ISampleGrabberCB{pu


root@terminal:~$ su ./mariamole