libeblearntools
|
00001 /*************************************************************************** 00002 * Copyright (C) 2010 by Pierre Sermanet * 00003 * pierre.sermanet@gmail.com * 00004 * All rights reserved. 00005 * 00006 * Redistribution and use in source and binary forms, with or without 00007 * modification, are permitted provided that the following conditions are met: 00008 * * Redistributions of source code must retain the above copyright 00009 * notice, this list of conditions and the following disclaimer. 00010 * * Redistributions in binary form must reproduce the above copyright 00011 * notice, this list of conditions and the following disclaimer in the 00012 * documentation and/or other materials provided with the distribution. 00013 * * Redistribution under a license not approved by the Open Source 00014 * Initiative (http://www.opensource.org) must display the 00015 * following acknowledgement in all advertising material: 00016 * This product includes software developed at the Courant 00017 * Institute of Mathematical Sciences (http://cims.nyu.edu). 00018 * * The names of the authors may not be used to endorse or promote products 00019 * derived from this software without specific prior written permission. 00020 * 00021 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 00022 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 00023 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 00024 * DISCLAIMED. IN NO EVENT SHALL ThE AUTHORS BE LIABLE FOR ANY 00025 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 00026 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 00027 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 00028 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 00029 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 00030 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 00031 ***************************************************************************/ 00032 00033 #ifndef CAMERA_MAC_HPP_ 00034 #define CAMERA_MAC_HPP_ 00035 00036 #ifdef __LINUX__ 00037 00038 #include <fcntl.h> /* low-level i/o */ 00039 #include <unistd.h> 00040 #include <errno.h> 00041 #include <malloc.h> 00042 00043 #endif 00044 00045 namespace ebl { 00046 00048 // constructors & initializations 00049 00050 template <typename Tdata> 00051 camera_mac<Tdata>::camera_mac(const char *device, int height_, int width_, 00052 bool grayscale_, bool mode_rgb_) 00053 : camera<Tdata>(height_, width_), started(false), 00054 nbuffers(grayscale_ ? 1 : 3), buffers(new void*[nbuffers]), 00055 sizes(new int[nbuffers]), mode_rgb(mode_rgb_) { 00056 cout << "Initializing Mac camera from device " << device 00057 << " to " << height_ << "x" << width_ << endl; 00058 } 00059 00060 template <typename Tdata> 00061 camera_mac<Tdata>::~camera_mac() { 00062 if (buffers) 00063 delete buffers; 00064 if (sizes) 00065 delete sizes; 00066 } 00067 00069 // frame grabbing 00070 #ifdef __LINUX__ 00071 template <typename Tdata> 00072 void camera_mac<Tdata>::start() { 00073 started = true; 00074 } 00075 #endif 00076 template <typename Tdata> 00077 idx<Tdata> camera_mac<Tdata>::grab() { 00078 if(mode_rgb) { 00079 // convert yuv to rgb 00080 idx<float> fyuv(height,width,nbuffers); 00081 idx_copy(frame,fyuv); 00082 idx<float> frame_frgb(height,width,nbuffers); 00083 yuv_to_rgb(fyuv ,frame_frgb); 00084 idx<Tdata> frame_rgb(height,width,nbuffers); 00085 idx_copy(frame_frgb,frame_rgb); 00086 frame = frame_rgb; 00087 } 00088 frame_id_++; 00089 return this->postprocess(); 00090 } 00091 00092 } // end namespace ebl 00093 00094 #endif /* CAMERA_MAC_HPP_ */