You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
(59) |
Jun
(40) |
Jul
(59) |
Aug
(81) |
Sep
(14) |
Oct
(9) |
Nov
(22) |
Dec
(1) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(25) |
Feb
(3) |
Mar
(27) |
Apr
(14) |
May
(15) |
Jun
(112) |
Jul
(44) |
Aug
(7) |
Sep
(18) |
Oct
(34) |
Nov
(17) |
Dec
(20) |
2006 |
Jan
(12) |
Feb
|
Mar
(1) |
Apr
|
May
|
Jun
(3) |
Jul
(1) |
Aug
|
Sep
|
Oct
|
Nov
(1) |
Dec
(11) |
From: Dominic L. <ma...@us...> - 2004-07-26 14:44:49
|
Update of /cvsroot/robotflow/RobotFlow/Generic/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19126 Modified Files: Makefile.am Added Files: USleep.cc Log Message: added USleep Index: Makefile.am =================================================================== RCS file: /cvsroot/robotflow/RobotFlow/Generic/src/Makefile.am,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** Makefile.am 31 May 2004 20:15:33 -0000 1.4 --- Makefile.am 26 Jul 2004 14:44:40 -0000 1.5 *************** *** 12,16 **** KDNode.cc \ KDPQueue.cc \ ! KDTree.cc libRF_Generic_la_LDFLAGS = -release $(LT_RELEASE) --- 12,17 ---- KDNode.cc \ KDPQueue.cc \ ! KDTree.cc \ ! USleep.cc libRF_Generic_la_LDFLAGS = -release $(LT_RELEASE) --- NEW FILE: USleep.cc --- #ifndef _USLEEP_CC_ #define _USLEEP_CC_ #include "BufferedNode.h" #include "Timer.h" #include <unistd.h> #include <sys/time.h> #include <unistd.h> class USleep; DECLARE_NODE(USleep) /*Node * @name USleep * @category RobotFlow:Generic * @description Wait a given time. * * @parameter_name MICROSECONDS * @parameter_description The time required to sleep * @parameter_type int * * @output_name OUTPUT * @output_description Nothing * END*/ class USleep : public BufferedNode { //outputs int outputID; //parameters int m_sleep_time; //local variables struct timespec m_tStartTime; public: USleep(string nodeName, ParameterSet params) : BufferedNode(nodeName, params) { //inputs //outputs outputID = addOutput("OUTPUT"); //parameters m_sleep_time = dereference_cast<int>(parameters.get("MICROSECONDS")); //getting starting time value vGetSystemTime( &m_tStartTime ); } void calculate(int output_id, int count, Buffer &out) { //TO DO: Study the possibility to use Jean-Marc's driver for // real time clock ("/dev/rtc") to do this //NOTE: This is to be used to calculate relatively short periods // of time (max ~30 min) long l_lDiffTime; struct timespec l_tEndTime; //getting new time value vGetSystemTime( &l_tEndTime ); //calculating time difference (microseconds) l_lDiffTime = lUsBetweenTimes( &m_tStartTime, &l_tEndTime ); if( m_sleep_time < l_lDiffTime ) { //cerr << "Processing taking too long by " << (l_lDiffTime - m_sleep_time) << " us." << endl; //getting new start time vGetSystemTime( &m_tStartTime ); } //Makes the current thread sleep for some microseconds else { thread_usleep( m_sleep_time - l_lDiffTime ); //getting new start time vAddUsToTime( m_sleep_time, &m_tStartTime ); } out[count] = ObjectRef(Bool::alloc(true)); }//calculate }; #endif |
From: Dominic L. <ma...@us...> - 2004-07-26 14:33:06
|
Update of /cvsroot/robotflow/RobotFlow/Vision/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16923/src Modified Files: Makefile.am Added Files: Binarize.cc CSymbol.cc CTextLine.cc ExtractSentence.cc ExtractSentence_v2.cc NewSymbolIdentify.cc Posterize.cc RectAnalyser.cc RectBoundaries.cc StatIntensityAnalyser.cc Surround.cc SymbolCounter.cc SymbolExtractor.cc SymbolSegmenter.cc Log Message: added SymbolRecognition blocks --- NEW FILE: RectAnalyser.cc --- #ifndef _RECT_ANALYSER_CC_ #define _RECT_ANALYSER_CC_ #include "BufferedNode.h" #include "CRect.h" #include <math.h> #include "misc.h" #include "net_types.h" #include "Vector.h" class RectAnalyser; DECLARE_NODE(RectAnalyser) /*Node * * @name RectAnalyser * @category RobotFlow:Vision * @description Extracts information about a CRect. * * @input_name CRECT * @input_type CRect * @input_description Blob bounding box (CRect) * * @output_name HEIGHT * @output_type int * @output_description Height of the blob (in pixels) * * @output_name WIDTH * @output_type int * @output_description Width of the blob (in pixels) * * @output_name AREA * @output_type int * @output_description Area of the blob contained in the rect * * @output_name X_RELATIVE_CENTER_OF_GRAVITY * @output_type int * @output_description Number of pixels between the left boundary of the blob and its center of gravity * * @output_name Y_RELATIVE_CENTER_OF_GRAVITY * @output_type int * @output_description Number of pixels between the top of the blob and its center of gravity END*/ class RectAnalyser : public BufferedNode { int mRectID; int mHeightID; int mWidthID; int mAreaID; int mXCenterID; int mYCenterID; public: RectAnalyser(string nodeName, ParameterSet params) : BufferedNode(nodeName, params) { mRectID = addInput("CRECT"); mHeightID = addOutput("HEIGHT"); mWidthID = addOutput("WIDTH"); mAreaID = addOutput("AREA"); mXCenterID = addOutput("X_RELATIVE_CENTER_OF_GRAVITY"); mYCenterID = addOutput("Y_RELATIVE_CENTER_OF_GRAVITY"); } void calculate(int output_id, int count, Buffer &out) { //getting input CRect &myRect = object_cast<CRect>(getInput(mRectID,count)); //extraction rect info int height = myRect.Height(); int width = myRect.Width(); int area = myRect.Area(); double centerX, centerY; int x1, y1, x2, y2, relativeCenterX, relativeCenterY; myRect.get_center_of_gravity(centerX, centerY); myRect.get_values(x1, y1, x2, y2); relativeCenterX = static_cast<int>(centerX) - x1; relativeCenterY = static_cast<int>(centerY) - y1; //set output (*outputs[mHeightID].buffer)[count] = ObjectRef (Int::alloc( height )); (*outputs[mWidthID].buffer)[count] = ObjectRef (Int::alloc( width )); (*outputs[mAreaID].buffer)[count] = ObjectRef (Int::alloc( area )); (*outputs[mXCenterID].buffer)[count] = ObjectRef (Int::alloc( relativeCenterX )); (*outputs[mYCenterID].buffer)[count] = ObjectRef (Int::alloc( relativeCenterY )); }//calculate }; #endif --- NEW FILE: NewSymbolIdentify.cc --- #ifndef _NEW_SYMBOL_IDENTIFY_CC_ #define _NEW_SYMBOL_IDENTIFY_CC_ #include "BufferedNode.h" #include "Vector.h" class NewSymbolIdentify; using namespace std; DECLARE_NODE(NewSymbolIdentify) /*Node * * @name NewSymbolIdentify * @category RobotFlow:EMIB * @description Identify symbol from neural network output * * @input_name INPUT * @input_type Vector<float> * @input_description neural network output vector * * @output_name SYMBOL_ID * @output_type int * @output_description Found symbol ID * * @parameter_name THRESHOLD * @parameter_type float * @parameter_value 0.80 * @parameter_description Recognition threshold * END*/ class NewSymbolIdentify : public BufferedNode { private: int m_inputID; int m_symbolID; float m_threshold; static const int SYMBOL_NONE; public: NewSymbolIdentify(string nodeName, ParameterSet params) : BufferedNode(nodeName, params) { m_inputID = addInput("INPUT"); m_symbolID = addOutput("SYMBOL_ID"); m_threshold = dereference_cast<float>(parameters.get("THRESHOLD")); } void calculate(int output_id, int count, Buffer &out) { Vector<float> &input_vect = object_cast<Vector<float> >(getInput(m_inputID,count)); int max_index = find_max(input_vect); if (max_index > 0) { if (input_vect[max_index] > m_threshold) { (*outputs[m_symbolID].buffer)[count] = ObjectRef(Int::alloc(max_index)); } else { (*outputs[m_symbolID].buffer)[count] = ObjectRef(Int::alloc(SYMBOL_NONE)); } } else { (*outputs[m_symbolID].buffer)[count] = ObjectRef(Int::alloc(SYMBOL_NONE)); } }//calculate int find_max(Vector<float> &input_vect) { float max_value = 0; int max_index = SYMBOL_NONE; for (int i = 0; i < input_vect.size(); i++) { if (input_vect[i] > max_value) { max_index = i; max_value = input_vect[i]; } } return max_index; } }; const int NewSymbolIdentify::SYMBOL_NONE = -1; #endif --- NEW FILE: ExtractSentence_v2.cc --- #ifndef _EXTRACTSENTENCE_V2_CC_ #define _EXTRACTSENTENCE_V2_CC_ #include "BufferedNode.h" #include "CSymbol.h" #include "CTextLine.h" #include "Vector.h" #include <iostream> class ExtractSentence_v2; bool IsAbove(void *, void *); DECLARE_NODE(ExtractSentence_v2) /*Node * * @name ExtractSentence_v2 * @category RobotFlow:Vision * @description Extract * * @input_name SYMBOL_LIST * @input_type Vector<ObjectRef> * @input_description Data about the extracted symbols * * @input_name DICT * @input_type Vector<String> * @input_description Dictionnary * * @parameter_name VERTICAL_TOLERANCE * @parameter_type float * @parameter_value 0.5 * @parameter_description Determines how strict the definition of a line is. * * @parameter_name HORIZONTAL_TOLERANCE * @parameter_type float * @parameter_value 0.8 * @parameter_description Determines how wide a space has to be to be considered an end of word. * * @output_name SENTENCE * @output_type string * @output_description A string corresponding to the sentence read * * @output_name ORIGINAL_TEXT * @output_type string * @output_description Original Text one letter at a time. * END*/ class ExtractSentence_v2 : public BufferedNode { int mInputID; int mDictID; int mOutputID; int mOriginalID; vector<CTextLine*> mLineVector; double mVerticalTolerance; double mHorizontalTolerance; public: ExtractSentence_v2(string nodeName, ParameterSet params) : BufferedNode(nodeName, params) { mInputID = addInput("SYMBOL_LIST"); mDictID = addInput("DICT"); mOutputID = addOutput("SENTENCE"); mOriginalID = addOutput("ORIGINAL_TEXT"); mVerticalTolerance = dereference_cast<float>(parameters.get("VERTICAL_TOLERANCE")); mHorizontalTolerance = dereference_cast<float>(parameters.get("HORIZONTAL_TOLERANCE"));; } /////////////////////////////////////////////////////////////////////////////// // Inserts a character in proper text line /////////////////////////////////////////////////////////////////////////////// void PlaceInLine(CSymbol & letterRead) { int i = 0; int NbLines = mLineVector.size(); bool linePlaced = false; // find whether letter belongs to an existing line for ( i = 0; (i < NbLines) && !linePlaced ; i++) { if ( mLineVector[i]->Contains(letterRead) ) { mLineVector[i]->Insert(letterRead); linePlaced = true; } } // if we couldn't find a line for this letter, we create a new one if ( !linePlaced ) { CTextLine * pNewLine = new CTextLine(letterRead, mVerticalTolerance, mHorizontalTolerance); mLineVector.push_back(pNewLine); } } /////////////////////////////////////////////////////////////////////////////// // Sorts lines according to vertical position /////////////////////////////////////////////////////////////////////////////// void SortLines() { sort(mLineVector.begin(), mLineVector.end(), IsAbove); } /////////////////////////////////////////////////////////////////////////////// // Extracts a sentence from data /////////////////////////////////////////////////////////////////////////////// void calculate(int output_id, int count, Buffer &out) { ObjectRef dataInValue = getInput(mInputID, count); Vector<String> &dict = object_cast<Vector<String> >(getInput(mDictID,count)); cerr<<"dict size "<<dict.size()<<endl; //invalid input, returning empty string! if(dataInValue->isNil()) { out[count] = ObjectRef(new String("")); return; } Vector<ObjectRef> &inBuff = object_cast<Vector<ObjectRef> > (dataInValue); mLineVector.clear(); int NbSymbols = inBuff.size(); //extract symbols and place in appropriate line //input are (max nnet output id, x1,y1,x2,y2, all network output) for (int i = 0; i < NbSymbols; i++) { Vector<float> data = object_cast <Vector<float> > (inBuff[i]); int SymbolId = (int)data[0]; int x1 = (int)data[1]; int y1 = (int)data[2]; int x2 = (int)data[3]; int y2 = (int)data[4]; int width = x2 - x1; int height = y2 - y1; int centerX = x1 + width/2; int centerY = y1 + height/2; //copy neural network output vector<float> temp_vector(max(0,data.size() - 5)); for (int j = 5; j < data.size(); j++) { temp_vector[j - 5] = data[j]; } CSymbol letterRead( SymbolId, centerX, centerY, width, height,temp_vector); PlaceInLine(letterRead); } // Sort all lines in top to bottom order SortLines(); // Place line content in a string int j; int nbLines = mLineVector.size(); string tempResult = ""; string sentence = ""; string original_sentence = ""; for (j = 0; j < nbLines; j++) { list<vector<vector<float> > > vect_list; mLineVector[j]->GetString_v2(tempResult,vect_list); original_sentence += tempResult; for (list<vector<vector<float> > >::iterator iter = vect_list.begin(); iter != vect_list.end(); iter++) { sentence += find_word((*iter),dict); sentence += " "; } original_sentence += "-"; sentence += "-"; // end of line symbol } // return resulting sentence (*outputs[mOutputID].buffer)[count] = ObjectRef (new String(sentence)); (*outputs[mOriginalID].buffer)[count] = ObjectRef (new String(original_sentence)); }//calculate string find_word(vector<vector<float> > &prob, Vector<String> &dict) { float p[10][36]; int i,j; bool isWord=true; float wordprob=1, numberprob=1; for (i=0;i<prob.size();i++) { if (prob[i].size()!=36) { cerr << "ca marche pas pantoute " << prob[i].size() << endl; throw new GeneralException("PROBABILITY SIZE MISMATCH",__FILE__,__LINE__); } for (j=0;j<36;j++) { p[i][j]=prob[i][j]; } p[i][0]=p[i][24]; } //check for number of word for (i=0;i<prob.size();i++) { float wp=-.99, np=-.99; for (j=0;j<10;j++) if (p[i][j]>np) np=p[i][j]; for (j=10;j<36;j++) if (p[i][j]>wp) wp=p[i][j]; wordprob *= (.5+.5*wp); numberprob *= .5+.5*np; } if (wordprob>numberprob) isWord = true; else isWord = false; // cerr << "isword = " << isWord << endl; if (isWord) { //We have a word int best_id=-1; float best_prob=-1; for (i=0;i<dict.size();i++) { float pr=1; string word = dict[i]; if (word.size()!=prob.size()) continue; for (j=0;j<word.size();j++) { //int id=int(word[j]); //cerr << id << " "; float pp= .5+.5*p[j][word[j]-'A'+10]; if (pp<.03) pp=.03; // cerr << pp << " "; pr*=pp; } // cerr << pr << endl; if (pr > best_prob) { best_id=i; best_prob=pr; } } if (best_id==-1) return string(); if (pow(best_prob,1.0f/prob.size())<.4) return string("?"); return dict[best_id]; } else { //we have a string of digits string number; for (i=0;i<prob.size();i++) { float best_prob=-2; int best_id=0; for (j=0;j<10;j++) { if (p[i][j]>best_prob) { best_id=j; best_prob=p[i][j]; } } number += '0'+best_id; } return number; } } };//end class /////////////////////////////////////////////////////////////////////////////// // Comparison function which states if a line should be placed before or // after another in a left to right reading order. To be used with sort function /////////////////////////////////////////////////////////////////////////////// /* bool IsAbove(void * A, void * B) { CTextLine *lineA = (CTextLine*) A; CTextLine *lineB = (CTextLine*) B; if ( lineA->GetVerticalPosition() < lineB->GetVerticalPosition() ) { return true; } return false; } */ #endif --- NEW FILE: SymbolExtractor.cc --- #ifndef _SYMBOL_EXTRACTOR_CC_ #define _SYMBOL_EXTRACTOR_CC_ #include "CRect.h" #include "BufferedNode.h" #include "ComponentsData.h" #include "assert.h" class SymbolExtractor; DECLARE_NODE(SymbolExtractor) /*Node * @name SymbolExtractor * @category RobotFlow:Vision * @description No description available * @parameter_name CHANNEL * @parameter_type int * @parameter_value 0 * @parameter_description Channel from which to extract the symbol * @parameter_name WIDTH * @parameter_type int * @parameter_value 320 * @parameter_description Width of the image (in pixels) * @parameter_name HEIGHT * @parameter_type int * @parameter_value 240 * @parameter_description Height of the image (in pixels) * @parameter_name DEPTH * @parameter_type int * @parameter_value 2 * @parameter_description Depth of the image (in bytes per pixel) * @input_name DATA * @input_description Extracted components data * @input_type ComponentsData * @input_name INDEX * @input_description Index of the symbol to extract * @input_type int * @output_name SYMBOL * @output_type CRect * @output_description CRect describing the symbol extracted from given channel END*/ class SymbolExtractor : public BufferedNode { //inputs int dataID; int indexID; //outputs int rectID; //parameters int m_width; int m_height; int m_depth; int m_channel; ObjectRef m_symbol; public: /////////////////////////////////////////////////////////////////////////////// // constructor /////////////////////////////////////////////////////////////////////////////// SymbolExtractor(string nodeName, ParameterSet params) : BufferedNode(nodeName, params), m_symbol(NULL) { //inputs dataID = addInput("DATA"); indexID = addInput("INDEX"); //outputs rectID = addOutput("SYMBOL"); //parameters m_width = dereference_cast<int>(parameters.get("WIDTH")); m_height = dereference_cast<int>(parameters.get("HEIGHT")); m_depth = dereference_cast<int>(parameters.get("DEPTH")); m_channel = dereference_cast<int>(parameters.get("CHANNEL")); m_symbol = nilObject; } /////////////////////////////////////////////////////////////////////////////// // Extract a blob from specified channel /////////////////////////////////////////////////////////////////////////////// void calculate (int output_id, int count, Buffer &out) { ObjectRef inputValue = getInput(dataID,count); ObjectRef indexRef = getInput(indexID, count); ComponentsData &inData = object_cast<ComponentsData>(inputValue); int index = dereference_cast<int>(indexRef); // extract channel data list<CRect*> &rectList = inData.get_color_components(m_channel); // channel should not be empty TBACP error management? assert(rectList.size() != 0); int i; // a negative index tells the block to use the biggest rect if (index < 0) { list<CRect*>::iterator largerRectIter = rectList.end(); int maxArea = 0; int currentArea = 0; for ( list<CRect*>::iterator rectIter = rectList.begin(); rectIter != rectList.end(); rectIter++ ) { currentArea = (*rectIter)->Area(); if ( currentArea > maxArea) { largerRectIter = rectIter; maxArea = currentArea; } } // We found the largest rectangle if (largerRectIter != rectList.end() ) { m_symbol = ObjectRef( new CRect( **largerRectIter ) ); } } // a positive index tells the block to use the specified rect else { // go to element indexed list<CRect*>::iterator rectIter = rectList.begin(); for (i = 0; i < index && rectIter != rectList.end(); i++) { rectIter++; } // We found the specified rectangle if ( rectIter != rectList.end() ) { m_symbol = ObjectRef( new CRect( **rectIter ) ); } } out[count] = m_symbol; }//calculate_behavior }; #endif --- NEW FILE: SymbolSegmenter.cc --- #ifndef _SYMBOL_SEGMENTER_CC_ #define _SYMBOL_SEGMENTER_CC_ #include <math.h> #include <vector> #include "CRect.h" #include "BufferedNode.h" #include "ComponentsData.h" #include "Image.h" #include "assert.h" using namespace std; class SymbolSegmenter; DECLARE_NODE(SymbolSegmenter) /*Node * @name SymbolSegmenter * @category RobotFlow:Vision * @description No description available * @input_name IMAGE * @input_description Original unprocessed image * @input_type Image * @input_name SYMBOL * @input_description Symbol to segment * @input_type CRect * @output_name SYMBOL_COUNT * @output_description Number of symbols after segmentation * @output_type int END*/ /* * @output_name DATA * @output_description Components of the segmented symbol * @output_type ComponentsData */ class SymbolSegmenter : public BufferedNode { //inputs int mImageID; int mSymbolID; //outputs int mDataID; int mCountID; ObjectRef mImageData; ObjectRef mSymbolData; vector<float> mVerticalProjection; list<int> mCutPointsList; int mSubWidth; int mSubHeight; public: /////////////////////////////////////////////////////////////////////////////// // constructor /////////////////////////////////////////////////////////////////////////////// SymbolSegmenter(string nodeName, ParameterSet params) : BufferedNode(nodeName, params) { cerr << "Begin SymbolSegmenter: constructor" << endl; //inputs mImageID = addInput("IMAGE"); mSymbolID = addInput("SYMBOL"); //outputs /*mDataID = addOutput("DATA");*/ mCountID = addOutput("SYMBOL_COUNT"); //parameters /*m_width = dereference_cast<int>(parameters.get("WIDTH")); m_height = dereference_cast<int>(parameters.get("HEIGHT")); m_depth = dereference_cast<int>(parameters.get("DEPTH")); m_channel = dereference_cast<int>(parameters.get("CHANNEL")); m_symbol = nilObject; */ mImageData = nilObject; mSymbolData = nilObject; mSubWidth = 0; mSubHeight = 0; cerr << "End SymbolSegmenter: constructor" << endl; } /////////////////////////////////////////////////////////////////////////////// // --- /////////////////////////////////////////////////////////////////////////////// void calculate (int output_id, int count, Buffer &out) { cerr << "Begin SymbolSegmenter: Calculate" << endl; // Extracting inputs mImageData = getInput(mImageID, count); mSymbolData = getInput(mSymbolID, count); // Return zero values if inputs are invalid if(mImageData->isNil() || mSymbolData->isNil()) { /*(*outputs[mMaxIntensityID].buffer)[count] = ObjectRef (Float::alloc( 0 ));*/ (*outputs[mCountID].buffer)[count] = ObjectRef (Int::alloc( 0 )); cerr << "Invalid inputs" << endl; return; } //Acquiring symbol CRect &myRect = object_cast<CRect>(mSymbolData); int x1,y1,x2,y2; myRect.get_values(x1,y1,x2,y2); cerr << "Corner values: (" <<x1 << "," << y1 << ") (" << x2 << "," << y2 << ")" << endl; mSubWidth = x2 - x1; mSubHeight = y2 - y1; assert( mSubWidth > 0 && mSubHeight > 0); // Projecting vertically region of interest ProjectSubImage(x1,y1,x2,y2); FindCutPoints(); int nbSymbols = mCutPointsList.size() + 1; (*outputs[mCountID].buffer)[count] = ObjectRef (Int::alloc(nbSymbols)); cerr << "End SymbolSegmenter: calculate" << endl; }//calculate_behavior void ProjectSubImage(int x1, int y1, int x2, int y2) { cerr << "Begin SymbolSegmenter: ProjectSubImage" << endl; // Intialise projection vector mVerticalProjection.resize(mSubWidth); Image &image = object_cast<Image>(mImageData); // Extract subimage data int fullWidth = image.get_width(); unsigned short *pSourceImage = (unsigned short*) image.get_data(); int x,y; int index = 0; int redValue, greenValue, blueValue; int currentIndex; short currentPixel; const int pixelSize = 0x001F; // Project subimage vertically by summing the elements of each column for ( x = x1; x <= x2; x++) { mVerticalProjection[index] = 0; for ( y = y1; y <= y2; y++) { // Get pixel at position x,y currentIndex = ( y * fullWidth ) + x; currentPixel = pSourceImage[currentIndex]; // Compute pixel intensity and store in array: // Color value is stocked as 0BBB BBGG GGGR RRRR redValue = currentPixel & 0x001f; greenValue = (currentPixel & 0x03e0) >> 5; blueValue = (currentPixel & 0x7c00) >> 10; // The intensity on a 0-1 scale is given by 1/3(R+G+B) / pixeldepth mVerticalProjection[index] += (redValue + greenValue + blueValue)/3; } index++; } cerr << "End SymbolSegmenter: ProjectSubImage" << endl; }//ProjectSubImage void FindCutPoints() { cerr << "Begin SymbolSegmenter: FindCutPoints" << endl; // Compute the diffProject vector which measures the changes in intensity ///////////////////////////////////////////////////////////////////////// cerr << "Before SymbolSegmenter: new float[" <<mSubWidth << "]" << endl; float * diffProjection = new float[mSubWidth]; cerr << "After SymbolSegmenter: new float" << endl; int index; // First and last elements of vector set to 0 diffProjection[0] = 0; diffProjection[mSubWidth - 1] = 0; // Other elements n are set to the absolute value of the difference // between the next and the previous corresponding elements in the // vertical projection for ( index = 1; index < mSubWidth - 1 ; index++) { diffProjection[index] = fabs( mVerticalProjection[index+1] - mVerticalProjection[index-1]); } // Compute the average of both projection vectors ///////////////////////////////////////////////////////////////////////// float sumProjection = 0; float sumDiffProjection = 0; for (index = 0; index < mSubWidth; index++) { sumProjection += mVerticalProjection[index]; sumDiffProjection += diffProjection[index]; } float averageProjection = sumProjection / mSubWidth; float averageDiffProjection = sumDiffProjection / mSubWidth; // Compute the standard deviation of both projection vectors // std = sum( (xi - xaverage)^2/(number elements-1) )^1/2 ///////////////////////////////////////////////////////////////////////// float stdProjection = 0; float stdDiffProjection = 0; for (index = 0; index < mSubWidth; index++) { stdProjection += pow(mVerticalProjection[index] - averageProjection, 2); stdDiffProjection += pow(diffProjection[index] - averageDiffProjection, 2); } stdProjection /= (mSubWidth - 1); stdProjection = sqrt(stdProjection); stdDiffProjection /= (mSubWidth - 1); stdDiffProjection = sqrt(stdDiffProjection); //TBMCP used-defined parameters float pFactor = 0.5; float pdFactor = 0.5; // Compute the thresholds for both vectors and identify point where // values are above the threshold in both vectors ///////////////////////////////////////////////////////////////////////// float thresholdProjection = averageProjection + ( pFactor * stdProjection ); float thresholdDiffProjection = averageDiffProjection + ( pdFactor * stdDiffProjection ); mCutPointsList.clear(); for (index = 0; index < mSubWidth; index++) { if ( (mVerticalProjection[index] > thresholdProjection) && (diffProjection[index] > thresholdDiffProjection) ) { cerr << "FindCutPoints: Cut at "<< index << endl; mCutPointsList.push_back(index); } } delete [] diffProjection; cerr << "End SymbolSegmenter: FindCutPoints" << endl; }//Find Cut Points }; #endif --- NEW FILE: StatIntensityAnalyser.cc --- #ifndef _STAT_INTENSITY_ANALYSER_CC_ #define _STAT_INTENSITY_ANALYSER_CC_ #include <time.h> #include <stdlib.h> #include <assert.h> #include "Image.h" #include "BufferedNode.h" class StatIntensityAnalyser; DECLARE_NODE(StatIntensityAnalyser) /*Node * @name StatIntensityAnalyser * @category RobotFlow:Vision * @description Extracts statistical information about the intensity of an image * * @parameter_name FRACTION_ANALYSED * @parameter_type float * @parameter_value 0.1 * @parameter_description Fraction of pixels to analyse (on a 0-1 scale) * * @input_name IMAGE_IN * @input_type Image * @input_description Image to analyse. * * @output_name MAX_INTENSITY * @output_type float * @output_description Maximum intensity of analysed sample on a 0-1 scale * * @output_name MIN_INTENSITY * @output_type float * @output_description Minimum intensity of analysed sample on a 0-1 scale * END*/ class StatIntensityAnalyser : public BufferedNode { //inputs and outputs int mImageInID; int mMaxIntensityID; int mMinIntensityID; int mAverageIntensityID; // parameters float mFractionAnalysed; public: StatIntensityAnalyser(string nodeName, ParameterSet params) : BufferedNode(nodeName, params) { //inputs mImageInID = addInput("IMAGE_IN"); //outputs mMaxIntensityID = addOutput("MAX_INTENSITY"); mMinIntensityID = addOutput("MIN_INTENSITY"); //parameters mFractionAnalysed = dereference_cast<float>(parameters.get("FRACTION_ANALYSED")); } void calculate (int output_id, int count, Buffer &out) { // Extracting input ObjectRef dataInValue = getInput(mImageInID, count); // Return zero values if input is invalid if(dataInValue->isNil()) { (*outputs[mMaxIntensityID].buffer)[count] = ObjectRef (Float::alloc( 0 )); (*outputs[mMinIntensityID].buffer)[count] = ObjectRef (Float::alloc( 0 )); return; } // Acquiring image Image &image = object_cast<Image>(dataInValue); unsigned short *pSourceImage = (unsigned short*) image.get_data(); int imageWidth = image.get_width(); int imageHeight = image.get_height(); int imageSize = imageWidth * imageHeight; int redValue, greenValue, blueValue; float averageValue; int currentPixelIndex = 0; short currentPixelValue; const int pixelSize = 0x001F; int nbPixelsToAnalyse = (int) (imageSize * mFractionAnalysed); // Minimum value to have a relevant result if (nbPixelsToAnalyse < 2) { nbPixelsToAnalyse = 2; } vector<float> intensityVector; // Seed the random number generator srand((unsigned) time(NULL)); for(int i = 0; i < nbPixelsToAnalyse; i++) { currentPixelIndex = rand() % imageSize; // cerr << "CPI: " << currentPixelIndex << endl; assert ( currentPixelIndex < imageSize ); currentPixelValue = *( pSourceImage + currentPixelIndex ); // color value is stocked as 0BBB BBGG GGGR RRRR redValue = currentPixelValue & 0x001f; greenValue = (currentPixelValue & 0x03e0) >> 5; blueValue = (currentPixelValue & 0x7c00) >> 10; // The intensity on a 0-1 scale is given by 1/3(R+G+B) / pixeldepth averageValue = (redValue + greenValue + blueValue)/3; averageValue /= pixelSize; intensityVector.push_back(averageValue); } assert( intensityVector.size() == nbPixelsToAnalyse ); float maxIntensity = *(max_element( intensityVector.begin(), intensityVector.end() )); float minIntensity = *(min_element( intensityVector.begin(), intensityVector.end() )); (*outputs[mMaxIntensityID].buffer)[count] = ObjectRef (Float::alloc( maxIntensity )); (*outputs[mMinIntensityID].buffer)[count] = ObjectRef (Float::alloc( minIntensity )); }//calculate_behavior }; #endif --- NEW FILE: CSymbol.cc --- #include "CSymbol.h" #include "FlowException.h" DECLARE_TYPE(CSymbol); /////////////////////////////////////////////////////////////////////////////// // empty constructor /////////////////////////////////////////////////////////////////////////////// CSymbol::CSymbol(): mSymbolDescriptor(0), mCenterX(0), mCenterY(0), mHeight(0), mWidth(0) { } /////////////////////////////////////////////////////////////////////////////// // initialized constructor /////////////////////////////////////////////////////////////////////////////// CSymbol::CSymbol(int symbolDescriptor, int centerX, int centerY, int width, int height): mSymbolDescriptor(symbolDescriptor), mCenterX(centerX), mCenterY(centerY), mHeight(height), mWidth(width) { if (centerX < 0) mCenterX = 0; if (centerY < 0) mCenterY = 0; if (height < 0) mHeight = 0; if (width < 0) mWidth = 0; } CSymbol::CSymbol(int symbolDescriptor, int centerX, int centerY, int width, int height, vector<float> &nnet_output) : mSymbolDescriptor(symbolDescriptor), mCenterX(centerX), mCenterY(centerY), mHeight(height), mWidth(width), mNetOutput(nnet_output) { } /////////////////////////////////////////////////////////////////////////////// // Copy constructor /////////////////////////////////////////////////////////////////////////////// CSymbol::CSymbol(const CSymbol & initSymbol): mSymbolDescriptor(initSymbol.mSymbolDescriptor), mCenterX(initSymbol.mCenterX), mCenterY(initSymbol.mCenterY), mHeight(initSymbol.mHeight), mWidth(initSymbol.mWidth), mNetOutput(initSymbol.mNetOutput) { } /////////////////////////////////////////////////////////////////////////////// // destructor /////////////////////////////////////////////////////////////////////////////// CSymbol::~CSymbol() { } /////////////////////////////////////////////////////////////////////////////// // sets a symbol's parameters /////////////////////////////////////////////////////////////////////////////// void CSymbol::SetSymbol(int symbolDescriptor, int centerX, int centerY, int width, int height) { mSymbolDescriptor = symbolDescriptor; if (centerX < 0) { mCenterX = 0; } else { mCenterX = centerX; } if (centerY < 0) { mCenterY = 0; } else { mCenterY = centerY; } if (height < 0) { mHeight = 0; } else { mHeight = height; } if (width < 0) { mWidth = 0; } else { mWidth = width; } } //end of SetSymbol /////////////////////////////////////////////////////////////////////////////// // Returns the string corresponding to the current symbol /////////////////////////////////////////////////////////////////////////////// void CSymbol::GetSymbolName(string & resultString) const { const string SYMBOLNAME[40] = {"0","1","2","3","4","5","6","7","8","9", "A","B", "C", "D", "E","F", "G", "H","I", "J","K", "L","M","N","O", "P", "Q", "R", "S","T", "U", "V","W", "X", "Y", "Z", " RIGHT ", " DOWN ", " LEFT ", " UP "}; if (mSymbolDescriptor == -1) { resultString = "?"; } else { resultString = SYMBOLNAME[mSymbolDescriptor]; } } /////////////////////////////////////////////////////////////////////////////// // Print object description in given stream /////////////////////////////////////////////////////////////////////////////// void CSymbol::printOn(ostream &out) const { out << "<CSymbol "<<endl; out << "<Center_X "<< mCenterX <<" >"<<endl; out << "<Center_Y "<< mCenterY <<" >"<<endl; out << "<Height " << mHeight <<" >"<<endl; out << "<Width " << mWidth <<" >"<<endl; out << "<Symbol " << mSymbolDescriptor <<" >"<<endl; out<<" >\n"; } --- NEW FILE: CTextLine.cc --- #include "CTextLine.h" #include "FlowException.h" #include <assert.h> DECLARE_TYPE(CTextLine); /////////////////////////////////////////////////////////////////////////////// // Empty constructor /////////////////////////////////////////////////////////////////////////////// CTextLine::CTextLine() { // Should not be called assert(0); } /////////////////////////////////////////////////////////////////////////////// // Constructor /////////////////////////////////////////////////////////////////////////////// CTextLine::CTextLine(CSymbol & firstLetter, double verticalTolerance, double horizontalTolerance): mVerticalTolerance(verticalTolerance), mHorizontalTolerance(horizontalTolerance), mAverageWidth(firstLetter.GetWidth()) { if ( verticalTolerance < 0) mVerticalTolerance = 0; if ( horizontalTolerance < 0) mHorizontalTolerance = 0; int letterHeight = firstLetter.GetHeight(); mMinY = firstLetter.GetCenterY() - (int)( mVerticalTolerance * letterHeight ); mMaxY = firstLetter.GetCenterY() + (int)( mVerticalTolerance * letterHeight ); mMinHeight = (int) ( letterHeight * (1 - mVerticalTolerance) ); mMaxHeight = (int) ( letterHeight * (1 + mVerticalTolerance) ); Insert( firstLetter ); } /////////////////////////////////////////////////////////////////////////////// // Destructor /////////////////////////////////////////////////////////////////////////////// CTextLine::~CTextLine() { CSymbol * tmpLetter; //empty letter list while ( !mLetterList.empty() ) { tmpLetter = mLetterList.front(); mLetterList.pop_front(); delete tmpLetter; } } /////////////////////////////////////////////////////////////////////////////// // Sorts the line in reading order /////////////////////////////////////////////////////////////////////////////// void CTextLine::Sort() { mLetterList.sort(IsBefore); } /////////////////////////////////////////////////////////////////////////////// // Inserts a letter in the list /////////////////////////////////////////////////////////////////////////////// void CTextLine::Insert(CSymbol& letter) { int NbSymbols = mLetterList.size(); CSymbol * pNewLetter = new CSymbol(letter); mLetterList.push_back(pNewLetter); mAverageWidth = ( (NbSymbols * mAverageWidth) + letter.GetWidth() )/(NbSymbols+1); } /////////////////////////////////////////////////////////////////////////////// // Checks the vertical position of the letter center to verify if // letter is considered as part of the current line /////////////////////////////////////////////////////////////////////////////// bool CTextLine::Contains(CSymbol & letterToCompare) { int centerY = letterToCompare.GetCenterY(); int height = letterToCompare.GetHeight(); if ( centerY > mMinY && centerY < mMaxY && height > mMinHeight && height < mMaxHeight) { return true; } return false; } /////////////////////////////////////////////////////////////////////////////// // Get the string representing the sorted line /////////////////////////////////////////////////////////////////////////////// void CTextLine::GetString(string & resultString) { this->Sort(); resultString = ""; string tempString = ""; list<CSymbol*>::iterator iter = mLetterList.begin(); while ( iter != mLetterList.end() ) { (*iter)->GetSymbolName(tempString); resultString += tempString; CSymbol firstSymbol = **iter; // The list is not a random access container, so the only way to access // its next element is to advance it here iter++; if ( iter != mLetterList.end() ) { CSymbol nextSymbol = **(iter); if ( SpacePresentBetween( firstSymbol, nextSymbol )) { resultString += " "; } } } } void CTextLine::GetString_v2(string & resultString, list<vector<vector<float> > > &vect_list) { this->Sort(); resultString = ""; string tempString = ""; list<CSymbol*>::iterator iter = mLetterList.begin(); vector<vector<float> > my_vect; while ( iter != mLetterList.end() ) { (*iter)->GetSymbolName(tempString); resultString += tempString; my_vect.push_back((*iter)->GetNetVector()); CSymbol firstSymbol = **iter; // The list is not a random access container, so the only way to access // its next element is to advance it here iter++; if ( iter != mLetterList.end() ) { CSymbol nextSymbol = **(iter); if ( SpacePresentBetween( firstSymbol, nextSymbol )) { resultString += " "; //adding new word to the list vect_list.push_back(my_vect); //clear current word my_vect.clear(); } } else { //adding new word to the list vect_list.push_back(my_vect); } } } /////////////////////////////////////////////////////////////////////////////// // States whether the space between characters is sufficient to constitute a // word separation /////////////////////////////////////////////////////////////////////////////// bool CTextLine::SpacePresentBetween(const CSymbol & firstSymbol, const CSymbol & nextSymbol) { int firstCenterX = firstSymbol.GetCenterX(); int firstWidth = firstSymbol.GetWidth(); int nextCenterX = nextSymbol.GetCenterX(); int nextWidth = nextSymbol.GetWidth(); int spaceBetween = ( nextCenterX - nextWidth/2 ) - (firstCenterX + firstWidth/2); if ( spaceBetween > (mAverageWidth * mHorizontalTolerance) ) { return true; } return false; } /////////////////////////////////////////////////////////////////////////////// // Print object description in given stream /////////////////////////////////////////////////////////////////////////////// void CTextLine::printOn(ostream &out) const { out << "<CTextLine "<<endl; out << "<MinY "<< mMinY <<" >"<<endl; out << "<MaxY "<< mMaxY <<" >"<<endl; out<<" >\n"; //TBACP print all symbols contained in list } /////////////////////////////////////////////////////////////////////////////// // Comparison function which states if a letter should be placed before or // after another in a left to right reading order. To be used with sort function /////////////////////////////////////////////////////////////////////////////// bool IsBefore(void * A, void * B) { CSymbol *rectA = (CSymbol*) A; CSymbol *rectB = (CSymbol*) B; if (rectA->GetCenterX() < rectB->GetCenterX()) { return true; } return false; } --- NEW FILE: Surround.cc --- #ifndef _SURROUND_CC_ #define _SURROUND_CC_ #include "Image.h" #include "BufferedNode.h" class Surround; DECLARE_NODE(Surround) /*Node * @name Surround * @category RobotFlow:Vision * @description Converts an image to black and white values * * @input_name IMAGE_IN * @input_type Image * @input_description Image to convert. * * @output_name IMAGE_OUT * @output_type Image * @output_description Converted image. * * @parameter_name SPACING * @parameter_type int * @parameter_value 10 * @parameter_description number of bordering pixels (white) * END*/ class Surround : public BufferedNode { //inputs and outputs int mImageInID; int mImageOutID; int m_spacing; public: Surround(string nodeName, ParameterSet params) : BufferedNode(nodeName, params) { //inputs mImageInID = addInput("IMAGE_IN"); //outputs mImageOutID = addOutput("IMAGE_OUT"); //parameters m_spacing = dereference_cast<int>(parameters.get("SPACING")); } void calculate (int output_id, int count, Buffer &out) { Image &image = object_cast<Image>(getInput(mImageInID,count)); Image *new_image = Image::alloc(image.get_width() + 2 * m_spacing, image.get_height() + 2 * m_spacing, 2); unsigned short *data = (unsigned short*) new_image->get_data(); for (int i = 0; i < new_image->get_width() * new_image->get_height(); i++) { *data++ = 0x7fff; //white } //copy image for (int i = 0; i < image.get_height(); i++) { unsigned short *original_ptr = (unsigned short*) image.get_data(); original_ptr = & original_ptr[image.get_width() * i]; unsigned short *newimage_ptr = (unsigned short*) new_image->get_data(); newimage_ptr = &newimage_ptr[(new_image->get_width() * (i + m_spacing)) + m_spacing]; for (int j = 0; j < image.get_width(); j++) { //copy image *newimage_ptr++ = *original_ptr++; } } out[count] = ObjectRef(new_image); }//calculate_behavior }; #endif --- NEW FILE: SymbolCounter.cc --- #ifndef _SYMBOL_COUNTER_CC_ #define _SYMBOL_COUNTER_CC_ #include "CRect.h" #include "BufferedNode.h" #include "ComponentsData.h" #include "assert.h" class SymbolCounter; DECLARE_NODE(SymbolCounter) /*Node * @name SymbolCounter * @category RobotFlow:Vision * @description Counts the number of symbols of a given channel in an image. * @parameter_name CHANNEL * @parameter_type int * @parameter_value 0 * @parameter_description Channel from which to extract the symbol * @parameter_name DEPTH * @parameter_type int * @parameter_value 2 * @parameter_description Depth of the image (in bytes per pixel) * @input_name DATA * @input_description Extracted components data * @input_type ComponentsData * @output_name COUNT * @output_type int * @output_description The number of symbols in the image END*/ class SymbolCounter : public BufferedNode { //inputs int dataID; //outputs int countID; //parameters int m_depth; int m_channel; public: SymbolCounter(string nodeName, ParameterSet params) : BufferedNode(nodeName, params) { //inputs dataID = addInput("DATA"); //outputs countID = addOutput("COUNT"); //parameters m_depth = dereference_cast<int>(parameters.get("DEPTH")); m_channel = dereference_cast<int>(parameters.get("CHANNEL")); } // Count the number of blobs in channel void calculate (int output_id, int count, Buffer &out) { ObjectRef inputValue = getInput(dataID,count); ComponentsData &inData = object_cast<ComponentsData>(inputValue); // extract channel data list<CRect*> &rectList = inData.get_color_components(m_channel); // count the rectangles int rectCount = 0; double centerX = 0, centerY = 0; for (list<CRect*>::iterator rectIter = rectList.begin(); rectIter != rectList.end(); rectIter++) { (*rectIter)->get_center_of_gravity(centerX, centerY); //TBACP Tolerance value: how far from the mean we accept characters rectCount++; } out[count] = ObjectRef(Int::alloc(rectCount)); }//calculate_behavior }; #endif Index: Makefile.am =================================================================== RCS file: /cvsroot/robotflow/RobotFlow/Vision/src/Makefile.am,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** Makefile.am 23 Jul 2004 17:20:52 -0000 1.24 --- Makefile.am 26 Jul 2004 14:32:58 -0000 1.25 *************** *** 42,46 **** MultiColorTracker.cc \ JPEGLoadMemory.cc \ ! LoadImage.cc libVision_la_LDFLAGS = -release $(LT_RELEASE) $(PIXBUF_LIBS) $(GNOME_LIB) $(JPEG_LIB) --- 42,63 ---- MultiColorTracker.cc \ JPEGLoadMemory.cc \ ! LoadImage.cc \ ! Binarize.cc \ ! CSymbol.cc \ ! CTextLine.cc \ ! ExtractSentence.cc \ ! ExtractSentence_v2.cc \ ! NewSymbolIdentify.cc \ ! Posterize.cc \ ! RectAnalyser.cc \ ! RectBoundaries.cc \ ! StatIntensityAnalyser.cc \ ! Surround.cc \ ! SymbolCounter.cc \ ! SymbolExtractor.cc \ ! SymbolSegmenter.cc ! ! ! libVision_la_LDFLAGS = -release $(LT_RELEASE) $(PIXBUF_LIBS) $(GNOME_LIB) $(JPEG_LIB) --- NEW FILE: RectBoundaries.cc --- #ifndef _RECTBOUNDARIES_CC_ #define _RECTBOUNDARIES_CC_ #include "BufferedNode.h" #include "CRect.h" #include <math.h> #include "misc.h" #include "net_types.h" #include "Vector.h" class RectBoundaries; DECLARE_NODE(RectBoundaries) /*Node * * @name RectBoundaries * @category RobotFlow:Vision * @description Returns information about the CRect corner points * * @input_name CRECT * @input_type CRect * @input_description Blob bounding box (CRect) * * @output_name OUTPUT * @output_type Vector<float> * @output_description CRect corners position: x,y of upper-left corner followed by x,y of lower-right corner. * * END*/ class RectBoundaries : public BufferedNode { int m_rectID; int m_outputID; public: RectBoundaries(string nodeName, ParameterSet params) : BufferedNode(nodeName, params) { m_rectID = addInput("CRECT"); m_outputID = addOutput("OUTPUT"); } // Extracts the rectangle boundaries void calculate(int output_id, int count, Buffer &out) { //getting input CRect &myRect = object_cast<CRect>(getInput(m_rectID,count)); //creating a new vector Vector<float> *myVect = Vector<float>::alloc(4); int x1,y1,x2,y2; //getting rectangle boundaries myRect.get_values(x1,y1,x2,y2); //initialize the vector (*myVect)[0] = x1; (*myVect)[1] = y1; (*myVect)[2] = x2; (*myVect)[3] = y2; //set output out[count] = ObjectRef(myVect); }//calculate }; #endif --- NEW FILE: Posterize.cc --- #ifndef _POSTERIZE_CC_ #define _POSTERIZE_CC_ #include "Image.h" #include "BufferedNode.h" class Posterize; DECLARE_NODE(Posterize) /*Node * @name Posterize * @category RobotFlow:Vision * @description Converts an image to solid color values * * @parameter_name WIDTH * @parameter_type int * @parameter_value 320 * @parameter_description Width of the image. * * @parameter_name HEIGHT * @parameter_type int * @parameter_value 240 * @parameter_description Height of the image. * * @parameter_name THRESHOLD * @parameter_type float * @parameter_value 0.5 * @parameter_description Threshold value on a 0-1 scale (Value of intensity above which pixels will be considered as colored) * * @input_name IMAGE_IN * @input_type Image * @input_description Image to convert. * * @output_name IMAGE_OUT * @output_type Image * @output_description Converted image. END*/ class Posterize : public BufferedNode { //inputs and outputs int mImageInID; int mImageOutID; // parameters int mWidth; int mHeight; float mThreshold; Image* mpImage; public: Posterize(string nodeName, ParameterSet params) : BufferedNode(nodeName, params), mpImage(NULL) { //inputs mImageInID = addInput("IMAGE_IN"); //outputs mImageOutID = addOutput("IMAGE_OUT"); //parameters mWidth = dereference_cast<int>(parameters.get("WIDTH")); mHeight = dereference_cast<int>(parameters.get("HEIGHT")); mThreshold = dereference_cast<float>(parameters.get("THRESHOLD")); mpImage = Image::alloc(mWidth,mHeight,2); } void calculate (int output_id, int count, Buffer &out) { // Acquiring image Image &image = object_cast<Image>(getInput(mImageInID,count)); unsigned short *pSourceImage = (unsigned short*) image.get_data(); unsigned short *pDestinationImage = (unsigned short*)mpImage->get_data(); short currentPixel; int redValue, greenValue, blueValue; int nbPixels = mWidth * mHeight; float averageValue; const int pixelSize = 0x001F; for(int i = 0; i < nbPixels; i++) { currentPixel = *pSourceImage; // color value is stocked as 0BBB BBGG GGGR RRRR redValue = currentPixel & 0x001f; greenValue = (currentPixel & 0x03e0) >> 5; blueValue = (currentPixel & 0x7c00) >> 10; averageValue = (float)redValue/(float)pixelSize; if ( averageValue > mThreshold) { redValue = 0x001f; } else { redValue = 0x0000; } averageValue = (float)greenValue/(float)pixelSize; if ( averageValue > mThreshold) { greenValue = 0x03e0; } else { greenValue = 0x0000; } averageValue = (float)blueValue/(float)pixelSize; if ( averageValue > mThreshold) { blueValue = 0x7c00; } else { blueValue = 0x0000; } *pDestinationImage = redValue | greenValue | blueValue; pSourceImage++; pDestinationImage++; } out[count] = ObjectRef(mpImage); }//calculate_behavior }; #endif --- NEW FILE: Binarize.cc --- #ifndef _BINARIZE_CC_ #define _BINARIZE_CC_ #include "Image.h" #include "BufferedNode.h" class Binarize; DECLARE_NODE(Binarize) /*Node * @name Binarize * @category RobotFlow:Vision * @description Converts an image to black and white values * * @input_name THRESHOLD * @input_type float * @input_description Threshold value on a 0-1 scale (Value of intensity above which pixels will be considered black) * * @input_name IMAGE_IN * @input_type Image * @input_description Image to convert. * * @output_name IMAGE_OUT * @output_type Image * @output_description Converted image. END*/ class Binarize : public BufferedNode { //inputs and outputs int mImageInID; int mImageOutID; int mThresholdID; float mThreshold; Image* mpImage; public: Binarize(string nodeName, ParameterSet params) : BufferedNode(nodeName, params), mpImage(NULL) { //inputs mImageInID = addInput("IMAGE_IN"); mThresholdID = addInput("THRESHOLD"); //outputs mImageOutID = addOutput("IMAGE_OUT"); } void calculate (int output_id, int count, Buffer &out) { int width, height; // Reading threshold value mThreshold = dereference_cast<float>(getInput(mThresholdID,count)); // Acquiring image Image &image = object_cast<Image>(getInput(mImageInID,count)); width = image.get_width(); height = image.get_height(); unsigned short *pSourceImage = (unsigned short*) image.get_data(); mpImage = Image::alloc(width,height,2); //mpImage = new Image(width,height,2); unsigned short *pDestinationImage = (unsigned short*)mpImage->get_data(); short currentPixel; int redValue, greenValue, blueValue; int nbPixels = width * height; float averageValue = 0; const int pixelSize = 0x001F; for(int i = 0; i < nbPixels; i++) { currentPixel = *pSourceImage; // color value is stocked as 0BBB BBGG GGGR RRRR redValue = currentPixel & 0x001f; greenValue = (currentPixel & 0x03e0) >> 5; blueValue = (currentPixel & 0x7c00) >> 10; // The intensity on a 0-1 scale is given by 1/3(R+G+B) / pixeldepth averageValue = (redValue + greenValue + blueValue)/3; averageValue /= pixelSize; if (averageValue < mThreshold) { *pDestinationImage = 0x0000; // black value } else { *pDestinationImage = 0x7FFF; // white value } pSourceImage++; pDestinationImage++; } out[count] = ObjectRef(mpImage); }//calculate_behavior }; #endif --- NEW FILE: ExtractSentence.cc --- #ifndef _EXTRACTSENTENCE_V2_CC_ #define _EXTRACTSENTENCE_V2_CC_ #include "BufferedNode.h" #include "CSymbol.h" #include "CTextLine.h" #include "Vector.h" #include <iostream> class ExtractSentence; bool IsAbove(void *, void *); DECLARE_NODE(ExtractSentence) /*Node * * @name ExtractSentence * @category RobotFlow:Vision * @description Extract * * @input_name SYMBOL_LIST * @input_type Vector<ObjectRef> * @input_description Data about the extracted symbols * * @parameter_name VERTICAL_TOLERANCE * @parameter_type float * @parameter_value 0.5 * @parameter_description Determines how strict the definition of a line is. * * @parameter_name HORIZONTAL_TOLERANCE * @parameter_type float * @parameter_value 0.8 * @parameter_description Determines how wide a space has to be to be considered an end of word. * * @output_name SENTENCE * @output_type string * @output_description A string corresponding to the sentence read * END*/ class ExtractSentence : public BufferedNode { int mInputID; int mOutputID; vector<CTextLine*> mLineVector; double mVerticalTolerance; double mHorizontalTolerance; public: ExtractSentence(string nodeName, ParameterSet params) : BufferedNode(nodeName, params) { mInputID = addInput("SYMBOL_LIST"); mOutputID = addOutput("SENTENCE"); mVerticalTolerance = dereference_cast<float>(parameters.get("VERTICAL_TOLERANCE")); mHorizontalTolerance = dereference_cast<float>(parameters.get("HORIZONTAL_TOLERANCE"));; } /////////////////////////////////////////////////////////////////////////////// // Inserts a character in proper text line /////////////////////////////////////////////////////////////////////////////// void PlaceInLine(CSymbol & letterRead) { int i = 0; int NbLines = mLineVector.size(); bool linePlaced = false; // find whether letter belongs to an existing line for ( i = 0; (i < NbLines) && !linePlaced ; i++) { if ( mLineVector[i]->Contains(letterRead) ) { mLineVector[i]->Insert(letterRead); linePlaced = true; } } // if we couldn't find a line for this letter, we create a new one if ( !linePlaced ) { CTextLine * pNewLine = new CTextLine(letterRead, mVerticalTolerance, mHorizontalTolerance); mLineVector.push_back(pNewLine); } } /////////////////////////////////////////////////////////////////////////////// // Sorts lines according to vertical position /////////////////////////////////////////////////////////////////////////////// void SortLines() { sort(mLineVector.begin(), mLineVector.end(), IsAbove); } /////////////////////////////////////////////////////////////////////////////// // Extracts a sentence from data /////////////////////////////////////////////////////////////////////////////// void calculate(int output_id, int count, Buffer &out) { ObjectRef dataInValue = getInput(mInputID, count); if(dataInValue->isNil()) { out[count] = ObjectRef(new String("")); return; } Vector<ObjectRef> &inBuff = object_cast<Vector<ObjectRef> > (dataInValue); mLineVector.clear(); int NbSymbols = inBuff.size(); //extract symbols and place in appropriate line for (int i = 0; i < NbSymbols; i++) { Vector<float> data = object_cast <Vector<float> > (inBuff[i]); int SymbolId = (int)data[0]; int x1 = (int)data[1]; int y1 = (int)data[2]; int x2 = (int)data[3]; int y2 = (int)data[4]; int width = x2 - x1; int height = y2 - y1; int centerX = x1 + width/2; int centerY = y1 + height/2; CSymbol letterRead( SymbolId, centerX, centerY, width, height); PlaceInLine(letterRead); } // Sort all lines in top to bottom order SortLines(); // Place line content in a string int j; int nbLines = mLineVector.size(); string tempResult = ""; string sentence = ""; for (j = 0; j < nbLines; j++) { mLineVector[j]->GetString(tempResult); sentence += tempResult; sentence += "-"; // end of line symbol } // return resulting sentence out[count] = ObjectRef(new String(sentence)); }//calculate }; /////////////////////////////////////////////////////////////////////////////// // Comparison function which states if a line should be placed before or // after another in a left to right reading order. To be used with sort function /////////////////////////////////////////////////////////////////////////////// bool IsAbove(void * A, void * B) { CTextLine *lineA = (CTextLine*) A; CTextLine *lineB = (CTextLine*) B; if ( lineA->GetVerticalPosition() < lineB->GetVerticalPosition() ) { return true; } return false; } #endif |
From: Dominic L. <ma...@us...> - 2004-07-26 14:33:06
|
Update of /cvsroot/robotflow/RobotFlow/Vision/include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16923/include Modified Files: Makefile.am Added Files: CSymbol.h CTextLine.h Log Message: added SymbolRecognition blocks --- NEW FILE: CSymbol.h --- #ifndef _CSYMBOL_ #define _CSYMBOL_ #include <list> #include "Object.h" #include "CRect.h" #include <vector> using namespace std; /** CSymbol. A CSymbol is an object describing a letter extracted from an image. @author Catherine Proulx @version $Revision: 1.1 $ */ class CSymbol : public Object { public: CSymbol(); CSymbol(int symbolDescriptor, int centerX, int centerY, int width, int height); CSymbol(int symbolDescriptor, int centerX, int centerY, int width, int height, vector<float> &nnet_output); CSymbol(const CSymbol & initSymbol); virtual ~CSymbol(); void SetSymbol(int symbolDescriptor, int centerX, int centerY, int width, int height); void GetSymbolName(string & resultString) const; void printOn(ostream &out = cout) const; // Inline get functions int GetCenterX() const {return mCenterX;} int GetCenterY() const {return mCenterY;} int GetHeight() const {return mHeight;} int GetWidth() const {return mWidth;} int GetSymbol() const {return mSymbolDescriptor;} vector<float> GetNetVector() const {return mNetOutput;} private: // numerical ID of the symbol int mSymbolDescriptor; // Coordinates of the geometrical center of the letter (not center of gravity) int mCenterX; int mCenterY; // Height and width of the symbol (in pixels) int mHeight; int mWidth; vector<float> mNetOutput; }; #endif --- NEW FILE: CTextLine.h --- #ifndef _CTEXTLINE_ #define _CTEXTLINE_ #include <list> #include "Object.h" #include "CSymbol.h" using namespace std; bool IsBefore(void*, void*); /////////////////////////////////////////////////////////////////////////////// // CTextLine. // // A CTextLine is an object describing a line of text. In contains a list of CRect // describing the letters. // /////////////////////////////////////////////////////////////////////////////// class CTextLine : public Object { public: CTextLine(); // Ctor with a initializing CRect to set the line parameters CTextLine(CSymbol & firstLetter, double verticalTolerance, double horizontalTolerance); // Dtor Destructor virtual ~CTextLine(); // Sorting the letters from left to right void Sort(); // Insert a new letter in line void Insert(CSymbol &); // Checks if letter is part of current line according to its y coordinates bool Contains(CSymbol &); // Get the string corresponding to the sorted line void GetString(string & resultString); // Get the string corresponding to the sorted line void GetString_v2(string & resultString, list<vector<vector<float> > >&vect_list); // Print Object void printOn(ostream &out = cout) const; // Get the line vertical position (centerY of first character) int GetVerticalPosition() { return (mMinY + mMaxY)/2; } list<CSymbol*>& getSymbols(){return mLetterList;} private: // Determines whether there's a space between two characters bool SpacePresentBetween(const CSymbol&, const CSymbol&); // Minimum and minimum vertical center value for a letter to be considered // part of the line (upper bound and lower bounds) int mMinY; int mMaxY; // Maximum and minimum heights for a letter to be considered part of the line int mMinHeight; int mMaxHeight; // Average width of characters: used for deciding what is a space int mAverageWidth; // Tolerance on the regularity of the line // (even character height and vertical alignement) double mVerticalTolerance; // Tolerance on the spacing between characters double mHorizontalTolerance; ///The list of cells list<CSymbol*> mLetterList; }; #endif Index: Makefile.am =================================================================== RCS file: /cvsroot/robotflow/RobotFlow/Vision/include/Makefile.am,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Makefile.am 3 Jun 2002 18:29:08 -0000 1.6 --- Makefile.am 26 Jul 2004 14:32:57 -0000 1.7 *************** *** 13,17 **** ioctl_bt848.h \ types.h \ ! lines.h --- 13,19 ---- ioctl_bt848.h \ types.h \ ! lines.h \ ! CSymbol.h \ ! CTextLine.h |
From: Dominic L. <ma...@us...> - 2004-07-23 20:15:57
|
Update of /cvsroot/robotflow/RobotFlow/Devices/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv14321/src Modified Files: SNCRZ30.cc Log Message: working pan-tilt-zoom rel,abs commands Index: SNCRZ30.cc =================================================================== RCS file: /cvsroot/robotflow/RobotFlow/Devices/src/SNCRZ30.cc,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** SNCRZ30.cc 23 Jul 2004 20:13:04 -0000 1.4 --- SNCRZ30.cc 23 Jul 2004 20:15:48 -0000 1.5 *************** *** 124,128 **** RCPtr<Int> tilt = RelTiltValue; send_pan_tilt_relative_position(m_panSpeed,*pan,m_tiltSpeed, *tilt); ! } else { --- 124,129 ---- RCPtr<Int> tilt = RelTiltValue; send_pan_tilt_relative_position(m_panSpeed,*pan,m_tiltSpeed, *tilt); ! m_currentPan+=*pan; ! m_currentTilt+=*tilt; } else { *************** *** 130,133 **** --- 131,135 ---- RCPtr<Int> pan = RelPanValue; send_pan_tilt_relative_position(m_panSpeed,*pan,m_tiltSpeed, 0); + m_currentPan+=*pan; } *************** *** 135,138 **** --- 137,141 ---- RCPtr<Int> tilt = RelTiltValue; send_pan_tilt_relative_position(m_panSpeed,0,m_tiltSpeed,*tilt); + m_currentTilt+=*tilt; } } *************** *** 142,145 **** --- 145,150 ---- RCPtr<Int> tilt = AbsTiltValue; send_pan_tilt_absolute_position(m_panSpeed,*pan,m_tiltSpeed, *tilt); + m_currentPan = *pan; + m_currentTilt = *tilt; } else { *************** *** 147,150 **** --- 152,156 ---- RCPtr<Int> pan = AbsPanValue; send_pan_tilt_absolute_position(m_panSpeed,*pan,m_tiltSpeed, m_currentTilt); + m_currentPan = *pan; } *************** *** 152,155 **** --- 158,162 ---- RCPtr<Int> tilt = AbsTiltValue; send_pan_tilt_absolute_position(m_panSpeed,m_currentPan,m_tiltSpeed, *tilt); + m_currentTilt = *tilt; } |
From: Dominic L. <ma...@us...> - 2004-07-23 20:13:13
|
Update of /cvsroot/robotflow/RobotFlow/Devices/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13776/src Modified Files: SNCRZ30.cc Log Message: working pan-tilt-zoom rel,abs commands Index: SNCRZ30.cc =================================================================== RCS file: /cvsroot/robotflow/RobotFlow/Devices/src/SNCRZ30.cc,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** SNCRZ30.cc 23 Jul 2004 19:38:14 -0000 1.3 --- SNCRZ30.cc 23 Jul 2004 20:13:04 -0000 1.4 *************** *** 96,99 **** --- 96,104 ---- //connect to the camera connect(m_host); + + reset(); + + home(); + } *************** *** 114,127 **** ObjectRef RelTiltValue = getInput(m_tiltRelInID,count); ! if (!RelPanValue->isNil()) { RCPtr<Int> pan = RelPanValue; ! send_pan_tilt_relative_position(m_panSpeed,*pan,m_tiltSpeed, 0); } - if (!RelTiltValue->isNil()) { - RCPtr<Int> tilt = RelTiltValue; - send_pan_tilt_relative_position(m_panSpeed,0,m_tiltSpeed,*tilt); } ! //create new image --- 119,166 ---- ObjectRef RelTiltValue = getInput(m_tiltRelInID,count); ! //process relative commands ! if (!RelPanValue->isNil() && !RelTiltValue->isNil()) { RCPtr<Int> pan = RelPanValue; ! RCPtr<Int> tilt = RelTiltValue; ! send_pan_tilt_relative_position(m_panSpeed,*pan,m_tiltSpeed, *tilt); ! ! } ! else { ! if (!RelPanValue->isNil()) { ! RCPtr<Int> pan = RelPanValue; ! send_pan_tilt_relative_position(m_panSpeed,*pan,m_tiltSpeed, 0); ! } ! ! if (!RelTiltValue->isNil()) { ! RCPtr<Int> tilt = RelTiltValue; ! send_pan_tilt_relative_position(m_panSpeed,0,m_tiltSpeed,*tilt); ! } } + //process absolute commands + if (!AbsPanValue->isNil() && !AbsTiltValue->isNil()) { + RCPtr<Int> pan = AbsPanValue; + RCPtr<Int> tilt = AbsTiltValue; + send_pan_tilt_absolute_position(m_panSpeed,*pan,m_tiltSpeed, *tilt); + } + else { + if (!AbsPanValue->isNil()) { + RCPtr<Int> pan = AbsPanValue; + send_pan_tilt_absolute_position(m_panSpeed,*pan,m_tiltSpeed, m_currentTilt); + } + + if (!AbsTiltValue->isNil()) { + RCPtr<Int> tilt = AbsTiltValue; + send_pan_tilt_absolute_position(m_panSpeed,m_currentPan,m_tiltSpeed, *tilt); + } } ! //process zoom commands ! if (!ZoomValue->isNil()) { ! RCPtr<Int> zoom = ZoomValue; ! send_zoom_position(*zoom); ! m_currentZoom = *zoom; ! } ! ! //create new image *************** *** 132,138 **** //output all data ! (*outputs[m_panAbsOutID].buffer)[count] = nilObject; ! (*outputs[m_tiltAbsOutID].buffer)[count] = nilObject; ! (*outputs[m_zoomOutID].buffer)[count] = nilObject; (*outputs[m_imageOutID].buffer)[count] = ObjectRef(image); --- 171,177 ---- //output all data ! (*outputs[m_panAbsOutID].buffer)[count] = ObjectRef(Int::alloc(m_currentPan)); ! (*outputs[m_tiltAbsOutID].buffer)[count] = ObjectRef(Int::alloc(m_currentTilt)); ! (*outputs[m_zoomOutID].buffer)[count] = ObjectRef(Int::alloc(m_currentZoom)); (*outputs[m_imageOutID].buffer)[count] = ObjectRef(image); *************** *** 167,171 **** my_stream << "VISCA=81010605FF"; ! cerr.write(my_stream.str().c_str(),my_stream.str().size()); //send data --- 206,210 ---- my_stream << "VISCA=81010605FF"; ! //cerr.write(my_stream.str().c_str(),my_stream.str().size()); //send data *************** *** 173,176 **** --- 212,216 ---- //get reply + /* unsigned char buffer[1024]; //1k buffer int recv_size = my_socket.recv_packet(buffer,1024); *************** *** 182,185 **** --- 222,226 ---- cerr<<endl; + */ } *************** *** 199,203 **** ! cerr.write(my_stream.str().c_str(),my_stream.str().size()); //send data --- 240,244 ---- ! //cerr.write(my_stream.str().c_str(),my_stream.str().size()); //send data *************** *** 205,208 **** --- 246,250 ---- //get reply + /* unsigned char buffer[1024]; //1k buffer int recv_size = my_socket.recv_packet(buffer,1024); *************** *** 214,217 **** --- 256,260 ---- cerr<<endl; + */ } *************** *** 271,275 **** my_stream << "FF\r\n"; //end message ! cerr.write(my_stream.str().c_str(),my_stream.str().size()); //send data --- 314,318 ---- my_stream << "FF\r\n"; //end message ! //cerr.write(my_stream.str().c_str(),my_stream.str().size()); //send data *************** *** 277,280 **** --- 320,324 ---- //get reply + /* unsigned char buffer[1024]; //1k buffer int recv_size = my_socket.recv_packet(buffer,1024); *************** *** 286,295 **** cerr<<endl; } void SNCRZ30::send_pan_tilt_relative_position(unsigned int pan_speed, int pan_position, unsigned int tilt_speed, int tilt_position) { - cerr<<"send_pan_tilt_relative_position : start"<<endl; - network_socket my_socket(network_socket::TCP_STREAM_TYPE,m_port); my_socket.socket_connect(m_host.c_str()); --- 330,338 ---- cerr<<endl; + */ } void SNCRZ30::send_pan_tilt_relative_position(unsigned int pan_speed, int pan_position, unsigned int tilt_speed, int tilt_position) { network_socket my_socket(network_socket::TCP_STREAM_TYPE,m_port); my_socket.socket_connect(m_host.c_str()); *************** *** 344,348 **** my_stream << "FF\r\n"; //end message ! cerr.write(my_stream.str().c_str(),my_stream.str().size()); //send data --- 387,391 ---- my_stream << "FF\r\n"; //end message ! //cerr.write(my_stream.str().c_str(),my_stream.str().size()); //send data *************** *** 350,357 **** //get reply ! cerr<<"get reply "<<endl; unsigned char buffer[1024]; //1k buffer ! //int recv_size = my_socket.recv_packet(buffer,1024); ! int recv_size = 0; //print reply --- 393,400 ---- //get reply ! /* unsigned char buffer[1024]; //1k buffer ! int recv_size = my_socket.recv_packet(buffer,1024); ! //print reply *************** *** 361,365 **** cerr<<endl; ! cerr<<"send_pan_tilt_relative_position : endl"<<endl; } --- 404,408 ---- cerr<<endl; ! */ } *************** *** 391,395 **** my_stream << "FF\r\n"; //end message ! cerr.write(my_stream.str().c_str(),my_stream.str().size()); //send data --- 434,438 ---- my_stream << "FF\r\n"; //end message ! //cerr.write(my_stream.str().c_str(),my_stream.str().size()); //send data *************** *** 397,400 **** --- 440,444 ---- //get reply + /* unsigned char buffer[1024]; //1k buffer int recv_size = my_socket.recv_packet(buffer,1024); *************** *** 406,409 **** --- 450,454 ---- cerr<<endl; + */ } *************** *** 435,439 **** my_stream << "FF\r\n"; //end message ! cerr.write(my_stream.str().c_str(),my_stream.str().size()); //send data --- 480,484 ---- my_stream << "FF\r\n"; //end message ! //cerr.write(my_stream.str().c_str(),my_stream.str().size()); //send data *************** *** 441,444 **** --- 486,490 ---- //get reply + /* unsigned char buffer[1024]; //1k buffer int recv_size = my_socket.recv_packet(buffer,1024); *************** *** 450,454 **** cerr<<endl; ! } --- 496,500 ---- cerr<<endl; ! */ } |
From: Dominic L. <ma...@us...> - 2004-07-23 20:13:13
|
Update of /cvsroot/robotflow/RobotFlow/Devices/include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv13776/include Modified Files: SNCRZ30.h Log Message: working pan-tilt-zoom rel,abs commands Index: SNCRZ30.h =================================================================== RCS file: /cvsroot/robotflow/RobotFlow/Devices/include/SNCRZ30.h,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SNCRZ30.h 23 Jul 2004 18:50:57 -0000 1.2 --- SNCRZ30.h 23 Jul 2004 20:13:03 -0000 1.3 *************** *** 68,71 **** --- 68,74 ---- //variables Image m_image; + int m_currentPan; + int m_currentTilt; + int m_currentZoom; }; |
From: Dominic L. <ma...@us...> - 2004-07-23 19:38:24
|
Update of /cvsroot/robotflow/RobotFlow/Devices/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6614/src Modified Files: SNCRZ30.cc Log Message: working capture, still need some work to do for abs commands Index: SNCRZ30.cc =================================================================== RCS file: /cvsroot/robotflow/RobotFlow/Devices/src/SNCRZ30.cc,v retrieving revision 1.2 retrieving revision 1.3 diff -C2 -d -r1.2 -r1.3 *** SNCRZ30.cc 23 Jul 2004 18:50:58 -0000 1.2 --- SNCRZ30.cc 23 Jul 2004 19:38:14 -0000 1.3 *************** *** 131,136 **** m_image.rotate_180(*image); ! out[count] = ObjectRef(image); ! } --- 131,140 ---- m_image.rotate_180(*image); ! //output all data ! (*outputs[m_panAbsOutID].buffer)[count] = nilObject; ! (*outputs[m_tiltAbsOutID].buffer)[count] = nilObject; ! (*outputs[m_zoomOutID].buffer)[count] = nilObject; ! (*outputs[m_imageOutID].buffer)[count] = ObjectRef(image); ! } *************** *** 286,289 **** --- 290,295 ---- void SNCRZ30::send_pan_tilt_relative_position(unsigned int pan_speed, int pan_position, unsigned int tilt_speed, int tilt_position) { + cerr<<"send_pan_tilt_relative_position : start"<<endl; + network_socket my_socket(network_socket::TCP_STREAM_TYPE,m_port); my_socket.socket_connect(m_host.c_str()); *************** *** 344,350 **** //get reply unsigned char buffer[1024]; //1k buffer ! int recv_size = my_socket.recv_packet(buffer,1024); ! //print reply for (int i = 0; i < recv_size; i++) { --- 350,358 ---- //get reply + cerr<<"get reply "<<endl; unsigned char buffer[1024]; //1k buffer ! //int recv_size = my_socket.recv_packet(buffer,1024); ! int recv_size = 0; ! //print reply for (int i = 0; i < recv_size; i++) { *************** *** 353,357 **** cerr<<endl; ! } --- 361,365 ---- cerr<<endl; ! cerr<<"send_pan_tilt_relative_position : endl"<<endl; } *************** *** 452,456 **** int size = m_imageSocket.recv_packet((unsigned char*)buffer,32768); ! //cerr<<"update_data got size :"<<size<<endl; return process_image_data(buffer,size); --- 460,464 ---- int size = m_imageSocket.recv_packet((unsigned char*)buffer,32768); ! cerr<<"SNCRZ30::update_data got size :"<<size<<endl; return process_image_data(buffer,size); *************** *** 469,472 **** --- 477,482 ---- input_string += string(data,data_size); + cerr<<"SNCRZ30::process_image_data buffer size :"<<input_string.size()<<endl; + //LOOK FOR JPEG START MARKER int jpeg_start_marker_pos = input_string.find(string(JPEG_MARKER_START,2)); *************** *** 475,478 **** --- 485,489 ---- //LOOK FOR JPEG END MARKER if (jpeg_start_marker_pos != string::npos) { + //jpeg_end_marker_pos = input_string.rfind(string(JPEG_MARKER_END,2)); jpeg_end_marker_pos = input_string.find(string(JPEG_MARKER_END,2),jpeg_start_marker_pos); } *************** *** 498,505 **** unsigned char* jpeg_ptr = (unsigned char*) &input_string[jpeg_start_marker_pos]; ! //cerr<<"jpeg_start :"<<jpeg_start_marker_pos<<" jpeg_end : "<<jpeg_end_marker_pos<<endl; ! //cerr<<"JPEG SIZE : "<<jpeg_end_marker_pos - jpeg_start_marker_pos<<endl; ! //printf("JPEG MAGIC %2.2x %2.2x %2.2x %2.2x\n",jpeg_ptr[0],jpeg_ptr[1],jpeg_ptr[2],jpeg_ptr[3]); ! //printf("JPEG END %2.2x %2.2x\n",jpeg_ptr[jpeg_end_marker_pos - jpeg_start_marker_pos],jpeg_ptr[jpeg_end_marker_pos - jpeg_start_marker_pos + 1]); //cerr<<"create image"<<endl; --- 509,523 ---- unsigned char* jpeg_ptr = (unsigned char*) &input_string[jpeg_start_marker_pos]; ! cerr<<"jpeg_start :"<<jpeg_start_marker_pos<<" jpeg_end : "<<jpeg_end_marker_pos<<endl; ! cerr<<"JPEG SIZE : "<<jpeg_end_marker_pos - jpeg_start_marker_pos<<endl; ! ! if (jpeg_end_marker_pos - jpeg_start_marker_pos < 1000) { ! cerr<<"strange size : "<<jpeg_end_marker_pos - jpeg_start_marker_pos<<endl; ! input_string.erase(0, jpeg_end_marker_pos + 2); ! return img_num; ! } ! ! fprintf(stderr,"JPEG MAGIC %2.2x %2.2x %2.2x %2.2x\n",jpeg_ptr[0],jpeg_ptr[1],jpeg_ptr[2],jpeg_ptr[3]); ! fprintf(stderr,"JPEG END %2.2x %2.2x\n",jpeg_ptr[jpeg_end_marker_pos - jpeg_start_marker_pos],jpeg_ptr[jpeg_end_marker_pos - jpeg_start_marker_pos + 1]); //cerr<<"create image"<<endl; |
From: Dominic L. <ma...@us...> - 2004-07-23 18:51:17
|
Update of /cvsroot/robotflow/RobotFlow/Devices/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30799/src Modified Files: SNCRZ30.cc Log Message: almost working image + data Index: SNCRZ30.cc =================================================================== RCS file: /cvsroot/robotflow/RobotFlow/Devices/src/SNCRZ30.cc,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SNCRZ30.cc 23 Jul 2004 18:13:33 -0000 1.1 --- SNCRZ30.cc 23 Jul 2004 18:50:58 -0000 1.2 *************** *** 69,78 **** SNCRZ30::SNCRZ30(const std::string &host, int port) ! : m_socket(network_socket::TCP_STREAM_TYPE,port), m_image(320,240,3) { connect(m_host); } SNCRZ30::SNCRZ30(string nodeName, ParameterSet params) ! : BufferedNode(nodeName,params), m_port(80), m_socket(network_socket::TCP_STREAM_TYPE,80), m_image(320,240,3) { //inputs --- 69,78 ---- SNCRZ30::SNCRZ30(const std::string &host, int port) ! : m_imageSocket(network_socket::TCP_STREAM_TYPE,port), m_dataSocket(network_socket::TCP_STREAM_TYPE,port), m_image(320,240,3) { connect(m_host); } SNCRZ30::SNCRZ30(string nodeName, ParameterSet params) ! : BufferedNode(nodeName,params), m_port(80), m_imageSocket(network_socket::TCP_STREAM_TYPE,80), m_dataSocket(network_socket::TCP_STREAM_TYPE,80),m_image(320,240,3) { //inputs *************** *** 107,110 **** --- 107,127 ---- update_data(); + //get Inputs + ObjectRef AbsPanValue = getInput(m_panAbsInID,count); + ObjectRef AbsTiltValue = getInput(m_tiltAbsInID,count); + ObjectRef ZoomValue = getInput(m_zoomInID,count); + ObjectRef RelPanValue = getInput(m_panRelInID,count); + ObjectRef RelTiltValue = getInput(m_tiltRelInID,count); + + if (!RelPanValue->isNil()) { + RCPtr<Int> pan = RelPanValue; + send_pan_tilt_relative_position(m_panSpeed,*pan,m_tiltSpeed, 0); + } + + if (!RelTiltValue->isNil()) { + RCPtr<Int> tilt = RelTiltValue; + send_pan_tilt_relative_position(m_panSpeed,0,m_tiltSpeed,*tilt); + } + //create new image *************** *** 119,130 **** int SNCRZ30::connect(const std::string &host) { - m_socket.socket_connect(host.c_str()); - m_host = host; ! //send periodic images... ostringstream my_stream; my_stream << "GET http://"<<m_host<<":"<<m_port<<"/image?speed=0 HTTP/1.1\r\n"<<endl; ! int sent_size = m_socket.send_packet((unsigned char*)my_stream.str().c_str(), my_stream.str().size()); cerr<<"sent request size "<<sent_size<<endl; } --- 136,150 ---- int SNCRZ30::connect(const std::string &host) { + //connect on both sockets + m_imageSocket.socket_connect(host.c_str()); + //m_dataSocket.socket_connect(host.c_str()); + + m_host = host; ! //send periodic images on image socket... ostringstream my_stream; my_stream << "GET http://"<<m_host<<":"<<m_port<<"/image?speed=0 HTTP/1.1\r\n"<<endl; ! int sent_size = m_imageSocket.send_packet((unsigned char*)my_stream.str().c_str(), my_stream.str().size()); cerr<<"sent request size "<<sent_size<<endl; } *************** *** 431,435 **** char buffer[32768]; ! int size = m_socket.recv_packet((unsigned char*)buffer,32768); //cerr<<"update_data got size :"<<size<<endl; --- 451,455 ---- char buffer[32768]; ! int size = m_imageSocket.recv_packet((unsigned char*)buffer,32768); //cerr<<"update_data got size :"<<size<<endl; |
From: Dominic L. <ma...@us...> - 2004-07-23 18:51:17
|
Update of /cvsroot/robotflow/RobotFlow/Devices/include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv30799/include Modified Files: SNCRZ30.h Log Message: almost working image + data Index: SNCRZ30.h =================================================================== RCS file: /cvsroot/robotflow/RobotFlow/Devices/include/SNCRZ30.h,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** SNCRZ30.h 23 Jul 2004 18:13:32 -0000 1.1 --- SNCRZ30.h 23 Jul 2004 18:50:57 -0000 1.2 *************** *** 43,47 **** int process_image_data(char* data, int data_size); ! network_socket m_socket; --- 43,48 ---- int process_image_data(char* data, int data_size); ! network_socket m_imageSocket; ! network_socket m_dataSocket; |
From: Dominic L. <ma...@us...> - 2004-07-23 18:13:43
|
Update of /cvsroot/robotflow/RobotFlow/Devices/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24640/src Modified Files: Makefile.am Added Files: SNCRZ30.cc Log Message: first working version of SNCRZ30 device Index: Makefile.am =================================================================== RCS file: /cvsroot/robotflow/RobotFlow/Devices/src/Makefile.am,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** Makefile.am 31 May 2004 20:15:32 -0000 1.10 --- Makefile.am 23 Jul 2004 18:13:32 -0000 1.11 *************** *** 12,16 **** LaserDevice.cc \ V4L2Capture.cc \ ! CANON_VCC4.cc libDevices_la_LDFLAGS = -release $(LT_RELEASE) --- 12,17 ---- LaserDevice.cc \ V4L2Capture.cc \ ! CANON_VCC4.cc \ ! SNCRZ30.cc libDevices_la_LDFLAGS = -release $(LT_RELEASE) --- NEW FILE: SNCRZ30.cc --- #include <sstream> #include <fstream> #include <string> #include <time.h> #include "SNCRZ30.h" #include "Image.h" DECLARE_NODE(SNCRZ30); /*Node * * @name SNCRZ30 * @category RobotFlow:Devices * @description Sony SNCRZ30 Network Camera Pan-Tilt-Zoom + JPEG image driver. * * @input_name PAN_ABS_POS * @input_type int * @input_description Absolute Pan of the camera -880 to +880. (1/10 of degrees) * * @input_name TILT_ABS_POS * @input_type int * @input_description Absolute Tilt of the camera -300 to +300. (1/10 of degrees) * * @input_name PAN_REL_POS * @input_type int * @input_description Absolute Pan of the camera -880 to +880. (1/10 of degrees) * * @input_name TILT_REL_POS * @input_type int * @input_description Absolute Tilt of the camera -300 to +300. (1/10 of degrees) * * @parameter_name PAN_SPEED * @parameter_type int * @parameter_value 24 * @parameter_description Pan speed 0-24 * * @parameter_name TILT_SPEED * @parameter_type int * @parameter_value 20 * @parameter_description Tilt speed 0-20 * * @parameter_name HOST * @parameter_type string * @parameter_value localhost * * @input_name ZOOM * @input_type int * @input_description Absolute Zoom of the camera 1 (1X) to 24 (24X) * * @output_name PAN_POSITION * @output_type int * @output_description Returns the current pan position of the Camera * * @output_name TILT_POSITION * @output_type int * @output_description Returns the current tilt position of the Camera * * @output_name ZOOM_POSITION * @output_type int * @output_description Returns the current zoom position of the Camera * * @output_name IMAGE * @output_type Image * @output_description Return the image from the camera * END*/ using namespace std; SNCRZ30::SNCRZ30(const std::string &host, int port) : m_socket(network_socket::TCP_STREAM_TYPE,port), m_image(320,240,3) { connect(m_host); } SNCRZ30::SNCRZ30(string nodeName, ParameterSet params) : BufferedNode(nodeName,params), m_port(80), m_socket(network_socket::TCP_STREAM_TYPE,80), m_image(320,240,3) { //inputs m_panAbsInID = addInput("PAN_ABS_POS"); m_tiltAbsInID = addInput("TILT_ABS_POS"); m_panRelInID = addInput("PAN_REL_POS"); m_tiltRelInID = addInput("TILT_REL_POS"); m_zoomInID = addInput("ZOOM"); //outputs m_panAbsOutID = addOutput("PAN_POSITION"); m_tiltAbsOutID = addOutput("TILT_POSITION"); m_zoomOutID = addOutput("ZOOM_POSITION"); m_imageOutID = addOutput("IMAGE"); //parameters m_host = object_cast<String>(parameters.get("HOST")); m_panSpeed = dereference_cast<int>(parameters.get("PAN_SPEED")); m_tiltSpeed = dereference_cast<int>(parameters.get("TILT_SPEED")); //connect to the camera connect(m_host); } SNCRZ30::~SNCRZ30() { } void SNCRZ30::calculate(int output_id, int count, Buffer &out) { //read data from the socket update_data(); //create new image Image *image = Image::alloc(320,240,3); //rotate original image m_image.rotate_180(*image); out[count] = ObjectRef(image); } int SNCRZ30::connect(const std::string &host) { m_socket.socket_connect(host.c_str()); m_host = host; //send periodic images... ostringstream my_stream; my_stream << "GET http://"<<m_host<<":"<<m_port<<"/image?speed=0 HTTP/1.1\r\n"<<endl; int sent_size = m_socket.send_packet((unsigned char*)my_stream.str().c_str(), my_stream.str().size()); cerr<<"sent request size "<<sent_size<<endl; } void SNCRZ30::home() { network_socket my_socket(network_socket::TCP_STREAM_TYPE,m_port); my_socket.socket_connect(m_host.c_str()); //create reset command ostringstream my_stream; my_stream << "POST http://"<<m_host<<":"<<m_port<<"/command/ptzf.cgi HTTP/1.1\r\n"; my_stream << "Connection: Keep-Alive\r\n"; my_stream << "Cache-Control: no-cache\r\n"; my_stream << "Content-Length: 16\r\n\r\n"; my_stream << "VISCA=81010605FF"; cerr.write(my_stream.str().c_str(),my_stream.str().size()); //send data int sent_size = my_socket.send_packet((unsigned char*)my_stream.str().c_str(), my_stream.str().size()); //get reply unsigned char buffer[1024]; //1k buffer int recv_size = my_socket.recv_packet(buffer,1024); //print reply for (int i = 0; i < recv_size; i++) { cerr<<buffer[i]; } cerr<<endl; } void SNCRZ30::reset() { network_socket my_socket(network_socket::TCP_STREAM_TYPE,m_port); my_socket.socket_connect(m_host.c_str()); ostringstream my_stream; //create home command my_stream << "POST http://"<<m_host<<":"<<m_port<<"/command/ptzf.cgi HTTP/1.1\r\n"; my_stream << "Connection: Keep-Alive\r\n"; my_stream << "Cache-Control: no-cache\r\n"; my_stream << "Content-Length: 16\r\n\r\n"; my_stream << "VISCA=81010604FF"; cerr.write(my_stream.str().c_str(),my_stream.str().size()); //send data int sent_size = my_socket.send_packet((unsigned char*)my_stream.str().c_str(), my_stream.str().size()); //get reply unsigned char buffer[1024]; //1k buffer int recv_size = my_socket.recv_packet(buffer,1024); //print reply for (int i = 0; i < recv_size; i++) { cerr<<buffer[i]; } cerr<<endl; } void SNCRZ30::send_pan_tilt_absolute_position(unsigned int pan_speed, int pan_position, unsigned int tilt_speed, int tilt_position) { network_socket my_socket(network_socket::TCP_STREAM_TYPE,m_port); my_socket.socket_connect(m_host.c_str()); if (pan_position < -1700 || pan_position > 1700) { cerr<<"pan position : "<<pan_position<<" out of range"<<endl; pan_position = max(min(pan_position,1700), -1700); } if (tilt_position < -725 || tilt_position > 425) { cerr<<"tilt position : "<<tilt_position<<" out of range"<<endl; tilt_position = max(min(tilt_position,425), -725); } //limit pan & tilt speed pan_speed = max(min((int)pan_speed,0x18), 0); tilt_speed = max(min((int)tilt_speed,0x14), 0); pan_position = (pan_position * 144) / 100; tilt_position = (tilt_position * 2287) / 1000; //create pan tilt command ostringstream my_stream; my_stream << "POST http://"<<m_host<<":"<<m_port<<"/command/ptzf.cgi HTTP/1.1\r\n"; my_stream << "Connection: Keep-Alive\r\n"; my_stream << "Cache-Control: no-cache\r\n"; my_stream << "Content-Length: 36\r\n\r\n"; my_stream << "VISCA=81010602"; static const unsigned int mask1 = 0x000F; static const unsigned int mask2 = 0x00F0; static const unsigned int mask3 = 0x0F00; static const unsigned int mask4 = 0xF000; my_stream << std::hex<<((mask2 & pan_speed)>>4);//pan speed my_stream << std::hex<<((mask1 & pan_speed)); my_stream << std::hex<<((mask2 & tilt_speed)>>4);//tilt speed my_stream << std::hex<<((mask1 & tilt_speed)); my_stream << "0"<<std::hex<<((mask4 & pan_position)>>12); //pan position my_stream << "0"<<std::hex<<((mask3 & pan_position)>>8); my_stream << "0"<<std::hex<<((mask2 & pan_position)>>4); my_stream << "0"<<std::hex<<((mask1 & pan_position)); my_stream << "0"<<std::hex<<((mask4 & tilt_position)>>12); //tilt position my_stream << "0"<<std::hex<<((mask3 & tilt_position)>>8); my_stream << "0"<<std::hex<<((mask2 & tilt_position)>>4); my_stream << "0"<<std::hex<<((mask1 & tilt_position)); my_stream << "FF\r\n"; //end message cerr.write(my_stream.str().c_str(),my_stream.str().size()); //send data int sent_size = my_socket.send_packet((unsigned char*)my_stream.str().c_str(), my_stream.str().size()); //get reply unsigned char buffer[1024]; //1k buffer int recv_size = my_socket.recv_packet(buffer,1024); //print reply for (int i = 0; i < recv_size; i++) { cerr<<buffer[i]; } cerr<<endl; } void SNCRZ30::send_pan_tilt_relative_position(unsigned int pan_speed, int pan_position, unsigned int tilt_speed, int tilt_position) { network_socket my_socket(network_socket::TCP_STREAM_TYPE,m_port); my_socket.socket_connect(m_host.c_str()); if (pan_position < -1700 || pan_position > 1700) { cerr<<"pan position : "<<pan_position<<" out of range"<<endl; pan_position = max(min(pan_position,1700), -1700); } if (tilt_position < -725 || tilt_position > 425) { cerr<<"tilt position : "<<tilt_position<<" out of range"<<endl; tilt_position = max(min(tilt_position,425), -725); } //limit pan & tilt speed pan_speed = max(min((int)pan_speed,0x18), 0); tilt_speed = max(min((int)tilt_speed,0x14), 0); pan_position = (pan_position * 144) / 100; tilt_position = (tilt_position * 2287) / 1000; //create pan tilt command ostringstream my_stream; my_stream << "POST http://"<<m_host<<":"<<m_port<<"/command/ptzf.cgi HTTP/1.1\r\n"; my_stream << "Connection: Keep-Alive\r\n"; my_stream << "Cache-Control: no-cache\r\n"; my_stream << "Content-Length: 36\r\n\r\n"; my_stream << "VISCA=81010603"; static const unsigned int mask1 = 0x000F; static const unsigned int mask2 = 0x00F0; static const unsigned int mask3 = 0x0F00; static const unsigned int mask4 = 0xF000; my_stream << std::hex<<((mask2 & pan_speed)>>4);//pan speed my_stream << std::hex<<((mask1 & pan_speed)); my_stream << std::hex<<((mask2 & tilt_speed)>>4);//tilt speed my_stream << std::hex<<((mask1 & tilt_speed)); my_stream << "0"<<std::hex<<((mask4 & pan_position)>>12); //pan position my_stream << "0"<<std::hex<<((mask3 & pan_position)>>8); my_stream << "0"<<std::hex<<((mask2 & pan_position)>>4); my_stream << "0"<<std::hex<<((mask1 & pan_position)); my_stream << "0"<<std::hex<<((mask4 & tilt_position)>>12); //tilt position my_stream << "0"<<std::hex<<((mask3 & tilt_position)>>8); my_stream << "0"<<std::hex<<((mask2 & tilt_position)>>4); my_stream << "0"<<std::hex<<((mask1 & tilt_position)); my_stream << "FF\r\n"; //end message cerr.write(my_stream.str().c_str(),my_stream.str().size()); //send data int sent_size = my_socket.send_packet((unsigned char*)my_stream.str().c_str(), my_stream.str().size()); //get reply unsigned char buffer[1024]; //1k buffer int recv_size = my_socket.recv_packet(buffer,1024); //print reply for (int i = 0; i < recv_size; i++) { cerr<<buffer[i]; } cerr<<endl; } void SNCRZ30::send_zoom_position(unsigned int zoom_position) { network_socket my_socket(network_socket::TCP_STREAM_TYPE,m_port); my_socket.socket_connect(m_host.c_str()); zoom_position = max(min((int)zoom_position,0x4000),0); //25X zoom //create zoom command ostringstream my_stream; my_stream << "POST http://"<<m_host<<":"<<m_port<<"/command/ptzf.cgi HTTP/1.1\r\n"; my_stream << "Connection: Keep-Alive\r\n"; my_stream << "Cache-Control: no-cache\r\n"; my_stream << "Content-Length: 24\r\n\r\n"; my_stream << "VISCA=81010447"; //zoom command static const unsigned int mask1 = 0x000F; static const unsigned int mask2 = 0x00F0; static const unsigned int mask3 = 0x0F00; static const unsigned int mask4 = 0xF000; my_stream << "0"<<std::hex<<((mask4 & zoom_position)>>12); //zoom position my_stream << "0"<<std::hex<<((mask3 & zoom_position)>>8); my_stream << "0"<<std::hex<<((mask2 & zoom_position)>>4); my_stream << "0"<<std::hex<<((mask1 & zoom_position)); my_stream << "FF\r\n"; //end message cerr.write(my_stream.str().c_str(),my_stream.str().size()); //send data int sent_size = my_socket.send_packet((unsigned char*)my_stream.str().c_str(), my_stream.str().size()); //get reply unsigned char buffer[1024]; //1k buffer int recv_size = my_socket.recv_packet(buffer,1024); //print reply for (int i = 0; i < recv_size; i++) { cerr<<buffer[i]; } cerr<<endl; } void SNCRZ30::send_focus_position(unsigned int focus_position) { network_socket my_socket(network_socket::TCP_STREAM_TYPE,m_port); my_socket.socket_connect(m_host.c_str()); focus_position = max(min((int)focus_position,0xC000),0x1000); //create focus command ostringstream my_stream; my_stream << "POST http://"<<m_host<<":"<<m_port<<"/command/ptzf.cgi HTTP/1.1\r\n"; my_stream << "Connection: Keep-Alive\r\n"; my_stream << "Cache-Control: no-cache\r\n"; my_stream << "Content-Length: 24\r\n\r\n"; my_stream << "VISCA=81010448"; //focus command static const unsigned int mask1 = 0x000F; static const unsigned int mask2 = 0x00F0; static const unsigned int mask3 = 0x0F00; static const unsigned int mask4 = 0xF000; my_stream << "0"<<std::hex<<((mask4 & focus_position)>>12); //zoom position my_stream << "0"<<std::hex<<((mask3 & focus_position)>>8); my_stream << "0"<<std::hex<<((mask2 & focus_position)>>4); my_stream << "0"<<std::hex<<((mask1 & focus_position)); my_stream << "FF\r\n"; //end message cerr.write(my_stream.str().c_str(),my_stream.str().size()); //send data int sent_size = my_socket.send_packet((unsigned char*)my_stream.str().c_str(), my_stream.str().size()); //get reply unsigned char buffer[1024]; //1k buffer int recv_size = my_socket.recv_packet(buffer,1024); //print reply for (int i = 0; i < recv_size; i++) { cerr<<buffer[i]; } cerr<<endl; } int SNCRZ30::update_data() { //read data on socket char buffer[32768]; int size = m_socket.recv_packet((unsigned char*)buffer,32768); //cerr<<"update_data got size :"<<size<<endl; return process_image_data(buffer,size); } int SNCRZ30::process_image_data(char* data, int data_size) { static string input_string; //create an empty string static int img_num = 0; static char JPEG_MARKER_START[] = {0xff,0xd8}; static char JPEG_MARKER_END[] = {0xff,0xd9}; static char JPEG_COMMENT_START[] = {0xff,0xfe}; int initial_size = input_string.size(); input_string += string(data,data_size); //LOOK FOR JPEG START MARKER int jpeg_start_marker_pos = input_string.find(string(JPEG_MARKER_START,2)); int jpeg_end_marker_pos = string::npos; //LOOK FOR JPEG END MARKER if (jpeg_start_marker_pos != string::npos) { jpeg_end_marker_pos = input_string.find(string(JPEG_MARKER_END,2),jpeg_start_marker_pos); } //IF WE FOUND ALL MARKERS, WE HAVE A COMPLETE IMAGE if (jpeg_start_marker_pos != string::npos && jpeg_end_marker_pos != string::npos) { int jpeg_start_comment_pos = input_string.find(string(JPEG_COMMENT_START,2)); if (jpeg_start_comment_pos != string::npos) { //cerr<<"found comment at pos :"<<jpeg_start_comment_pos<<endl; static char JPEG_TABLE_START[] = {0xff,0xdb}; int jpeg_start_table_pos = input_string.find(string(JPEG_TABLE_START,2),jpeg_start_comment_pos); //clear comment for (int i = jpeg_start_comment_pos; i < jpeg_start_table_pos; i++) { input_string[i] = '\0'; } } //cerr<<"input string size (before): "<<input_string.size()<<endl; unsigned char* jpeg_ptr = (unsigned char*) &input_string[jpeg_start_marker_pos]; //cerr<<"jpeg_start :"<<jpeg_start_marker_pos<<" jpeg_end : "<<jpeg_end_marker_pos<<endl; //cerr<<"JPEG SIZE : "<<jpeg_end_marker_pos - jpeg_start_marker_pos<<endl; //printf("JPEG MAGIC %2.2x %2.2x %2.2x %2.2x\n",jpeg_ptr[0],jpeg_ptr[1],jpeg_ptr[2],jpeg_ptr[3]); //printf("JPEG END %2.2x %2.2x\n",jpeg_ptr[jpeg_end_marker_pos - jpeg_start_marker_pos],jpeg_ptr[jpeg_end_marker_pos - jpeg_start_marker_pos + 1]); //cerr<<"create image"<<endl; //char fname[256]; //sprintf(fname,"image.jpg",img_num++); //ofstream output(fname); //output.write((char*)jpeg_ptr,(jpeg_end_marker_pos + 2) - jpeg_start_marker_pos); //output.flush(); //output.close(); //cerr<<"decompress jpeg"<<endl; m_image.jpeg_decompress(jpeg_ptr,(jpeg_end_marker_pos + 2) - jpeg_start_marker_pos); //cerr<<"decompress done"<<endl; input_string.erase(0, jpeg_end_marker_pos + 2); //cerr<<"input string size (after) : "<<input_string.size()<<endl; img_num++; } return img_num; } |
From: Dominic L. <ma...@us...> - 2004-07-23 18:13:42
|
Update of /cvsroot/robotflow/RobotFlow/Devices/include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv24640/include Modified Files: Makefile.am Added Files: SNCRZ30.h Log Message: first working version of SNCRZ30 device --- NEW FILE: SNCRZ30.h --- #ifndef _SNCRZ30_H_ #define _SNCRZ30_H_ #include <string> #include "SocketStream.h" #include "Image.h" #include "BufferedNode.h" //First prototype of Sony SNC-RZ30N network camera //(C) Dominic Letourneau 2004 class SNCRZ30 : public BufferedNode{ public: SNCRZ30(string nodeName, ParameterSet params); ~SNCRZ30(); SNCRZ30(const std::string &host, int port = 80); virtual void calculate(int output_id, int count, Buffer &out); int connect(const std::string &host); void send_pan_tilt_absolute_position(unsigned int pan_speed, int pan_position, unsigned int tilt_speed, int tilt_position); void send_pan_tilt_relative_position(unsigned int pan_speed, int pan_position, unsigned int tilt_speed, int tilt_position); void send_zoom_position(unsigned int zoom_position); void send_focus_position(unsigned int focus_position); void reset(); void home(); int update_data(); private: int process_image_data(char* data, int data_size); network_socket m_socket; //inputs int m_panAbsInID; int m_tiltAbsInID; int m_panRelInID; int m_tiltRelInID; int m_zoomInID; //outputs int m_panAbsOutID; int m_tiltAbsOutID; int m_zoomOutID; int m_imageOutID; //parameters std::string m_host; int m_port; int m_panSpeed; int m_tiltSpeed; //variables Image m_image; }; #endif Index: Makefile.am =================================================================== RCS file: /cvsroot/robotflow/RobotFlow/Devices/include/Makefile.am,v retrieving revision 1.9 retrieving revision 1.10 diff -C2 -d -r1.9 -r1.10 *** Makefile.am 7 Apr 2004 13:00:18 -0000 1.9 --- Makefile.am 23 Jul 2004 18:13:32 -0000 1.10 *************** *** 8,10 **** videodev2.h \ videodevfix.h \ ! videodev.h --- 8,11 ---- videodev2.h \ videodevfix.h \ ! videodev.h \ ! SNCRZ30.h |
From: Dominic L. <ma...@us...> - 2004-07-23 17:21:01
|
Update of /cvsroot/robotflow/RobotFlow/Vision/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16342/Vision/src Modified Files: Makefile.am Log Message: updated Image class to be able to read and write jpeg data Index: Makefile.am =================================================================== RCS file: /cvsroot/robotflow/RobotFlow/Vision/src/Makefile.am,v retrieving revision 1.23 retrieving revision 1.24 diff -C2 -d -r1.23 -r1.24 *** Makefile.am 13 Jun 2004 19:44:11 -0000 1.23 --- Makefile.am 23 Jul 2004 17:20:52 -0000 1.24 *************** *** 44,50 **** LoadImage.cc ! libVision_la_LDFLAGS = -release $(LT_RELEASE) $(PIXBUF_LIBS) $(GNOME_LIB) ! INCLUDES = -I../include $(OVERFLOW_INCLUDE) $(PIXBUF_INCLUDE) install-data-local: --- 44,50 ---- LoadImage.cc ! libVision_la_LDFLAGS = -release $(LT_RELEASE) $(PIXBUF_LIBS) $(GNOME_LIB) $(JPEG_LIB) ! INCLUDES = -I../include $(OVERFLOW_INCLUDE) $(PIXBUF_INCLUDE) $(JPEG_INCLUDE) install-data-local: |
From: Dominic L. <ma...@us...> - 2004-07-23 17:21:01
|
Update of /cvsroot/robotflow/RobotFlow In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv16342 Modified Files: Makefile.am RobotFlow.spec.in configure.in Log Message: updated Image class to be able to read and write jpeg data Index: RobotFlow.spec.in =================================================================== RCS file: /cvsroot/robotflow/RobotFlow/RobotFlow.spec.in,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** RobotFlow.spec.in 31 May 2004 20:15:31 -0000 1.3 --- RobotFlow.spec.in 23 Jul 2004 17:20:52 -0000 1.4 *************** *** 46,50 **** --mandir=%{_mandir} \ --sysconfdir=%{_sysconfdir} \ ! --disable-static %{__make} --- 46,51 ---- --mandir=%{_mandir} \ --sysconfdir=%{_sysconfdir} \ ! --disable-static \ ! --disable-MARIE %{__make} Index: Makefile.am =================================================================== RCS file: /cvsroot/robotflow/RobotFlow/Makefile.am,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** Makefile.am 30 May 2004 12:34:07 -0000 1.18 --- Makefile.am 23 Jul 2004 17:20:51 -0000 1.19 *************** *** 12,16 **** EXTRA_DIST = RobotFlow.spec RobotFlow.spec.in ! SUBDIRS = Generic Pioneer2 Behaviors Vision Control Devices Probes FSM $(PLAYER_DIR) $(MARIE_DIR) rpm: dist --- 12,16 ---- EXTRA_DIST = RobotFlow.spec RobotFlow.spec.in ! SUBDIRS = Pioneer2 Generic Behaviors Vision Control Devices Probes FSM $(PLAYER_DIR) $(MARIE_DIR) rpm: dist Index: configure.in =================================================================== RCS file: /cvsroot/robotflow/RobotFlow/configure.in,v retrieving revision 1.43 retrieving revision 1.44 diff -C2 -d -r1.43 -r1.44 *** configure.in 22 Jul 2004 20:59:26 -0000 1.43 --- configure.in 23 Jul 2004 17:20:52 -0000 1.44 *************** *** 209,214 **** fi ! AC_SUBST(ACE_LIBS) ! AC_SUBST(ACE_INCLUDES) AC_SUBST(MARIE_LIBS) AC_SUBST(MARIE_INCLUDES) --- 209,214 ---- fi ! #AC_SUBST(ACE_LIBS) ! #AC_SUBST(ACE_INCLUDES) AC_SUBST(MARIE_LIBS) AC_SUBST(MARIE_INCLUDES) *************** *** 237,241 **** XML2_INCLUDE=`$XML2_CONFIG --cflags` XML2_LIB=`$XML2_CONFIG --libs` ! dnl Look for prefix, if not specified, use FlowDesigner default toolbox prefix --- 237,242 ---- XML2_INCLUDE=`$XML2_CONFIG --cflags` XML2_LIB=`$XML2_CONFIG --libs` ! JPEG_INCLUDE="-I/usr/include" ! JPEG_LIB="-L/usr/lib -ljpeg" dnl Look for prefix, if not specified, use FlowDesigner default toolbox prefix *************** *** 260,263 **** --- 261,266 ---- AC_SUBST(XML2_INCLUDE) AC_SUBST(XML2_LIB) + AC_SUBST(JPEG_INCLUDE) + AC_SUBST(JPEG_LIB) dnl Output Files (makefiles) |
From: Dominic L. <ma...@us...> - 2004-07-23 17:14:06
|
Update of /cvsroot/robotflow/RobotFlow/Vision/include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15079/include Modified Files: Image.h Log Message: added jpeg_load and jpeg_save from memory Index: Image.h =================================================================== RCS file: /cvsroot/robotflow/RobotFlow/Vision/include/Image.h,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Image.h 12 Mar 2003 16:37:33 -0000 1.5 --- Image.h 23 Jul 2004 17:13:56 -0000 1.6 *************** *** 32,35 **** --- 32,37 ---- Image(const Image & cpy); + Image (const std::string &jpegfile); + virtual ~Image(); *************** *** 60,63 **** --- 62,77 ---- virtual void destroy(); + int jpeg_compress(unsigned char* buffer, int max_size, int quality); + + void jpeg_decompress(const unsigned char* buffer, int size); + + void load_jpeg(const std::string &jpegfile); + + void save_jpeg(const std::string &jpegfile, int quality); + + void rotate_180(Image &rotated_image); + + void merge(Image &upperLeft, Image &upperRight, Image &lowerLeft, Image &lowerRight); + private: |
From: Dominic L. <ma...@us...> - 2004-07-23 17:14:06
|
Update of /cvsroot/robotflow/RobotFlow/Vision/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv15079/src Modified Files: Image.cc Log Message: added jpeg_load and jpeg_save from memory Index: Image.cc =================================================================== RCS file: /cvsroot/robotflow/RobotFlow/Vision/src/Image.cc,v retrieving revision 1.12 retrieving revision 1.13 diff -C2 -d -r1.12 -r1.13 *** Image.cc 15 Jul 2003 14:19:50 -0000 1.12 --- Image.cc 23 Jul 2004 17:13:56 -0000 1.13 *************** *** 20,23 **** --- 20,30 ---- #include "ObjectParser.h" #include "binio.h" + #include <assert.h> + #include <sstream> + #include <fstream> + + extern "C" { + #include <jpeglib.h> + } DECLARE_TYPE(Image); *************** *** 211,212 **** --- 218,620 ---- return new_image; } + + /* + * Initialize destination --- called by jpeg_start_compress + * before any data is actually written. + */ + METHODDEF(void) + init_destination (j_compress_ptr cinfo) + { + //cerr<<"init_destination"<<endl; + } + + /* + * Empty the output buffer --- called whenever buffer fills up. + */ + METHODDEF(boolean) + empty_output_buffer (j_compress_ptr cinfo) + { + //cerr<<"empty output buffer"<<endl; + return TRUE; + } + + + /* + * Terminate destination --- called by jpeg_finish_compress + * after all data has been written. + */ + METHODDEF(void) + term_destination (j_compress_ptr cinfo) + { + //cerr<<"term_destination"<<endl; + } + + //DECOMPRESS HANDLERS + + METHODDEF(void) + init_source (j_decompress_ptr cinfo) + { + //cerr<<"init_source"<<endl; + } + + METHODDEF(boolean) + fill_input_buffer(j_decompress_ptr cinfo) + { + //cerr<<"fill_input_buffer"<<endl; + } + + METHODDEF(void) + skip_input_data (j_decompress_ptr cinfo, long num_bytes) + { + //cerr<<"skip_input_data"<<endl; + } + + METHODDEF(boolean) + resync_to_restart(j_decompress_ptr cinfo, int desired) + { + //cerr<<"resync_to_restart"<<endl; + } + + METHODDEF(void) + term_source (j_decompress_ptr cinfo) + { + //cerr<<"term_source"<<endl; + } + + + int Image::jpeg_compress(unsigned char* buffer, int max_size, int quality) { + + struct jpeg_compress_struct cinfo; + struct jpeg_error_mgr jerr; + + cinfo.err = jpeg_std_error(&jerr); + jpeg_create_compress(&cinfo); + + //set destination to memory + struct jpeg_destination_mgr dest_mgr; + + //set function pointers + dest_mgr.init_destination = init_destination; + dest_mgr.empty_output_buffer = empty_output_buffer; + dest_mgr.term_destination = term_destination; + + dest_mgr.next_output_byte = buffer; + + dest_mgr.free_in_buffer = max_size; /* # of byte spaces remaining in buffer */ + cinfo.dest = &dest_mgr; + + //set other image params + cinfo.image_width = get_width(); /* image width and height, in pixels */ + cinfo.image_height = get_height(); + + switch(get_pixelsize()) { + case 1: + cinfo.input_components = 1; /* # of color components per pixel */ + cinfo.in_color_space = JCS_GRAYSCALE; + cinfo.data_precision = 8; //8 bpp + break; + + case 2: + cinfo.input_components = 3; /* # of color components per pixel */ + cinfo.in_color_space = JCS_RGB; /* colorspace of input image */ + cinfo.data_precision = 15; //15 bPP + break; + + case 3: + cinfo.input_components = 3; /* # of color components per pixel */ + cinfo.in_color_space = JCS_RGB; /* colorspace of input image */ + cinfo.data_precision = 24; //24 bPP + break; + } + + jpeg_set_defaults(&cinfo); + + jpeg_set_quality(&cinfo,quality,TRUE); /* set compression quality */ + + /* Make optional parameter settings here */ + jpeg_start_compress(&cinfo, TRUE); + + JSAMPROW row_pointer[1]; /* pointer to a single row */ + int row_stride; /* physical row width in buffer */ + + row_stride = get_width() * get_pixelsize(); /* JSAMPLEs per row in image_buffer */ + + unsigned char *image_buffer = get_data(); + + while (cinfo.next_scanline < cinfo.image_height) { + row_pointer[0] = & image_buffer[cinfo.next_scanline * row_stride]; + jpeg_write_scanlines(&cinfo, row_pointer, 1); + } + + jpeg_finish_compress(&cinfo); + + int size = max_size - dest_mgr.free_in_buffer; + + jpeg_destroy_compress(&cinfo); + + //cerr<<"jpeg compress size : "<<size<<endl; + + //output number of free bytes + return size; + } + + void Image::jpeg_decompress(const unsigned char* buffer, int size) { + + + int image_width; + int image_height; + + struct jpeg_decompress_struct cinfo; + + struct jpeg_error_mgr jerr; + + JSAMPROW row_pointer[1]; /* pointer to JSAMPLE row[s] */ + int row_stride; /* physical row width in output buffer */ + int crows=0; + + jpeg_source_mgr source_mgr; + + //set handlers + source_mgr.init_source = init_source; + source_mgr.fill_input_buffer = fill_input_buffer; + source_mgr.skip_input_data = skip_input_data; + source_mgr.resync_to_restart = resync_to_restart; + source_mgr.term_source = term_source; + //set data pointers + + source_mgr.next_input_byte = buffer; /* => next byte to read from buffer */ + source_mgr.bytes_in_buffer = size; /* # of bytes remaining in buffer */ + + + /* Step 1: allocate and initialize JPEG decompression object */ + + /* We set up the normal JPEG error routines, then override error_exit. */ + cinfo.err = jpeg_std_error(&jerr); + + /* Now we can initialize the JPEG decompression object. */ + jpeg_create_decompress(&cinfo); + + /* Step 2: specify data source (memory) */ + cinfo.src = &source_mgr; + + + /* Step 3: read file parameters with jpeg_read_header() */ + (void) jpeg_read_header(&cinfo, TRUE); + + /* We can ignore the return value from jpeg_read_header since + * (a) suspension is not possible with the stdio data source, and + * (b) we passed TRUE to reject a tables-only JPEG file as an error. + * See libjpeg.doc for more info. + */ + + /* Step 4: set parameters for decompression */ + + cinfo.out_color_space = JCS_RGB; + + /* In this example, we don't need to change any of the defaults set by + * jpeg_read_header(), so we do nothing here. + */ + + /* Step 5: Start decompressor */ + + (void) jpeg_start_decompress(&cinfo); + /* We can ignore the return value since suspension is not possible + * with the stdio data source. + */ + + /* We may need to do some setup of our own at this point before reading + * the data. After jpeg_start_decompress() we have the correct scaled + * output image dimensions available, as well as the output colormap + * if we asked for color quantization. + * In this example, we need to make an output work buffer of the right size. + */ + + /* JSAMPLEs per row in output buffer */ + row_stride = cinfo.output_width * cinfo.output_components; + + /* initialize new image */ + if (m_width != cinfo.image_width || + m_height != cinfo.image_height || + m_size != cinfo.output_components * cinfo.image_width * cinfo.image_height) { + + if (m_data) delete m_data; + + m_width = cinfo.image_width; + m_height = cinfo.image_height; + m_data = new unsigned char[m_width * m_height * cinfo.output_components]; + m_size = m_width * m_height * cinfo.output_components; + } + + + /* Step 6: while (scan lines remain to be read) */ + /* jpeg_read_scanlines(...); */ + + /* Here we use the library's state variable cinfo.output_scanline as the + * loop counter, so that we don't have to keep track ourselves. + */ + while (cinfo.output_scanline < cinfo.output_height) { + /* 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. + */ + row_pointer[0] = & m_data[crows * row_stride]; + (void) jpeg_read_scanlines(&cinfo, row_pointer, 1); + + crows++; + } + + /* Step 7: Finish decompression */ + + (void) jpeg_finish_decompress(&cinfo); + /* We can ignore the return value since suspension is not possible + * with the stdio data source. + */ + + /* Step 8: Release JPEG decompression object */ + + /* This is an important step since it will release a good deal of memory. */ + jpeg_destroy_decompress(&cinfo); + + + /* At this point you may want to check to see whether any corrupt-data + * warnings occurred (test whether jerr.pub.num_warnings is nonzero). + */ + + /* And we're done! */ + //return retval; + } + + Image::Image(const std::string &jpegfile) + : m_width(0), m_height(0), m_size(0), m_data(NULL) { + + load_jpeg(jpegfile); + } + + + void Image::load_jpeg(const std::string &jpegfile) { + + stringstream temp_stream; + int count = 0; + ifstream input_file(jpegfile.c_str(),ios::binary); + + if (!input_file) { + cerr<<"file not valid :"<<jpegfile<<endl; + } + else { + while(!input_file.eof()) { + char value; + input_file.read(&value,1); + + if (!input_file.eof()) { + temp_stream.write(&value,1); + count++; + } + } + if (count > 0) { + + //deallocate image if necessary + if (m_data) { + m_width = 0; + m_height = 0; + delete [] m_data; + m_data = NULL; + } + + jpeg_decompress((const unsigned char*)temp_stream.str().c_str(),temp_stream.str().size()); + } + } + + + input_file.close(); + + } + + void Image::save_jpeg(const std::string &jpegfile, int quality) { + + unsigned char buffer[320 * 240 * 3]; + + int size = jpeg_compress(buffer,320 * 240 * 3,quality); + + ofstream outfile(jpegfile.c_str(),ios::binary); + + outfile.write((char *)buffer,size); + + outfile.close(); + } + + + void Image::merge(Image &upperLeft, Image &upperRight, Image &lowerLeft, Image &lowerRight) { + + //could be removed once fully debugged + assert(upperLeft.get_width() == m_width / 2); + assert(upperLeft.get_height() == m_height / 2); + assert(upperRight.get_width() == m_width / 2); + assert(upperRight.get_height() == m_height / 2); + assert(lowerLeft.get_width() == m_width / 2); + assert(lowerLeft.get_height() == m_height / 2); + assert(lowerRight.get_width() == m_width / 2); + assert(lowerRight.get_height() == m_height / 2); + + //valid for all images + unsigned char* merge_imagePtr = get_data(); + unsigned char* part_imagePtr = NULL; + int merge_pixelsize = get_pixelsize(); + int merge_rowstride = merge_pixelsize * get_width(); + int part_rowstride = merge_rowstride / 2; + int half_width = get_width() / 2; + int half_height = get_height() / 2; + + //upper left copy + part_imagePtr = upperLeft.get_data(); + for(int i = 0; i < upperLeft.get_height(); i++) { + memcpy(&merge_imagePtr[i * merge_rowstride],&part_imagePtr[i * part_rowstride],part_rowstride); + } + + //upper right copy + part_imagePtr = upperRight.get_data(); + for(int i = 0; i < upperRight.get_height(); i++) { + memcpy(&merge_imagePtr[i * merge_rowstride + (half_width * merge_pixelsize)],&part_imagePtr[i * part_rowstride],part_rowstride); + } + + //lower left + part_imagePtr = lowerLeft.get_data(); + for(int i = 0; i < lowerLeft.get_height(); i++) { + memcpy(&merge_imagePtr[(i + half_height) * merge_rowstride],&part_imagePtr[i * part_rowstride],part_rowstride); + } + + //lower right + part_imagePtr = lowerRight.get_data(); + for(int i = 0; i < lowerRight.get_height(); i++) { + memcpy(&merge_imagePtr[(i + half_height) * merge_rowstride + (half_width * merge_pixelsize)],&part_imagePtr[i * part_rowstride],part_rowstride); + } + } + + void Image::rotate_180(Image &rotated_image) { + + if (rotated_image.get_size() != get_size()) { + cerr<<"Images not of same size"<<endl; + } + + unsigned char* rotated_ptr = rotated_image.get_data(); + unsigned char* self_ptr = &get_data()[get_size() -1]; + + for (int i = 0; i < get_width() * get_height(); i++) { + + switch( get_pixelsize()) { + case 3: + rotated_ptr[0] = *(self_ptr - 2); + rotated_ptr[1] = *(self_ptr -1); + rotated_ptr[2] = *(self_ptr); + break; + default: + cerr<<"Image::rotate_180 : unsupported size for rotation: "<<get_pixelsize()<<endl; + break; + } + //increment pointer + rotated_ptr += get_pixelsize(); + self_ptr -= get_pixelsize(); + } + + + + } |
From: Carle C. <car...@us...> - 2004-07-22 21:01:04
|
Update of /cvsroot/robotflow/RobotFlow/MARIE/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29368/src Added Files: MarieDataRaw.cpp Log Message: Add MarieDataRaw datatype --- NEW FILE: MarieDataRaw.cpp --- /* * MARIE - Mobile and Autonomous Robotics Integration Environment * Copyright (C) 2004 Carle Cote * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * You can contact MARIE development team at http://marie.sourceforge.net */ #include "MarieDataRaw.h" #include <sstream> #include <string> #include "MarieXMLDataFactory.h" #include "Vector.h" namespace marie { DECLARE_NODE(MarieDataRaw) /*Node * * @name MarieDataRaw * @category RobotFlow:MARIE:DATA * @description Save an object * * @input_name DATA_RAW * @input_type MarieDataRaw * @input_description MarieDataRaw object * * @input_name OBJREF * @input_type MarieDataRaw * @input_description MarieDataRaw object * * @input_name CUSTOM_ID * @input_type MarieDataRaw * @input_description MarieDataRaw object * * @output_name OBJREF * @output_description Range contained in the MarieDataRaw object * @output_type any * * @output_name DATA_RAW * @output_description Range contained in the MarieDataRaw object * @output_type MarieDataRaw * * @output_name CUSTOM_ID * @output_description Range contained in the MarieDataRaw object * @output_type string * END*/ DECLARE_TYPE2(DataRaw::ID,MarieDataRaw) using namespace std; MarieDataRaw::MarieDataRaw() : MarieObject("MarieDataRaw",ParameterSet()), m_isNode(false) { } MarieDataRaw::MarieDataRaw (const DataRaw &data) : MarieObject("MarieDataRaw",ParameterSet()), DataRaw(data), m_isNode(false) { } MarieDataRaw::MarieDataRaw(string nodeName, ParameterSet params) : MarieObject(nodeName,params), m_isNode(true) { //used as a BufferedNode, create inputs & outputs m_rawMarieInID = addInput("DATA_RAW"); m_rawMarieOutID = addOutput("DATA_RAW"); m_objRefOutID = addOutput("OBJREF"); m_customIDOutID = addOutput("CUSTOM_ID"); m_objRefInID = addInput("OBJREF"); m_customIDInID = addInput("CUSTOM_ID"); } void MarieDataRaw::calculate(int output_id, int count, Buffer &out) { if (m_isNode) { MarieDataRaw *dataRaw = NULL; //get all inputs ObjectRef dataInValue = getInput(m_rawMarieInID,count); ObjectRef objRefInValue = getInput(m_objRefInID,count); ObjectRef customIDInValue = getInput(m_customIDInID,count); ObjectRef objRefOutValue = nilObject; ObjectRef customIDOutValue = nilObject; //initialize new CommandMotor if(!dataInValue->isNil()) { RCPtr<MarieDataRaw> dataPtr = dataInValue; dataRaw = new MarieDataRaw(*dataPtr); stringstream tempStr(dataRaw->getRawData()); tempStr >> objRefOutValue; customIDOutValue = ObjectRef(new String(dataRaw->getCustomID())); } else { if (!objRefInValue->isNil() && !customIDInValue->isNil()) { dataRaw = new MarieDataRaw(); ostringstream tempStr; tempStr << objRefInValue; dataRaw->setRawData(tempStr.str()); RCPtr<String> customIDPtr = customIDInValue; dataRaw->setCustomID(*customIDPtr); } } //set new rotation & velocity if (dataRaw) { (*outputs[m_rawMarieOutID].buffer)[count] = ObjectRef(dataRaw); (*outputs[m_objRefOutID].buffer)[count] = objRefOutValue; (*outputs[m_customIDOutID].buffer)[count] = customIDOutValue; } else { (*outputs[m_rawMarieOutID].buffer)[count] = nilObject; (*outputs[m_objRefOutID].buffer)[count] = nilObject; (*outputs[m_customIDOutID].buffer)[count] = nilObject; } } else //not a node... { out[count] = nilObject; } } void MarieDataRaw::printOn(ostream &out) const { MarieXMLDataFactory factory; //writing XML data string value = factory.toString((DataRaw&) (*this)); out.write(value.c_str(), value.size()); } void MarieDataRaw::readFrom(istream &in) { throw new GeneralException("readFrom not supported. Use the MarieLoad Node to read data from the stream.",__FILE__,__LINE__); } void MarieDataRaw::copyDataAbstract(DataAbstract *data) { if (data) { DataRaw *my_data = dynamic_cast<DataRaw*>(data); if (my_data) { //((DataRaw*)this)->operator=(*my_data); this->DataRaw::operator=(*my_data); } else { throw new GeneralException(string("Unable to cast into DataRaw Abstract : ") + data->getID(),__FILE__,__LINE__); } } } } |
From: Carle C. <car...@us...> - 2004-07-22 21:01:04
|
Update of /cvsroot/robotflow/RobotFlow/MARIE/include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv29368/include Added Files: MarieDataRaw.h Log Message: Add MarieDataRaw datatype --- NEW FILE: MarieDataRaw.h --- /* * MARIE - Mobile and Autonomous Robotics Integration Environment * Copyright (C) 2004 Carle Cote * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA * * You can contact MARIE development team at http://marie.sourceforge.net */ // Prevent Multiple Inclusion #ifndef _MARIE_DATA_RAW_H_ #define _MARIE_DATA_RAW_H_ //FlowDesigner include #include "Object.h" #include "MarieObject.h" //MARIE data types include #include "DataRaw.h" namespace marie { class MarieDataRaw : public MarieObject, public DataRaw { public: MarieDataRaw(); MarieDataRaw (const DataRaw &data); //from BufferedNode MarieDataRaw(string nodeName, ParameterSet params); virtual void calculate(int output_id, int count, Buffer &out); virtual void printOn(ostream &out) const; virtual void readFrom(istream &in=cin); virtual void copyDataAbstract(DataAbstract *data); private: int m_rawMarieInID; int m_rawMarieOutID; int m_objRefInID; int m_customIDOutID; int m_objRefOutID; int m_customIDInID; bool m_isNode; }; } #endif |
From: Carle C. <car...@us...> - 2004-07-22 20:59:44
|
Update of /cvsroot/robotflow/RobotFlow In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28909 Modified Files: configure.in Log Message: Remove ACEXML lib dependencies, correct minor bugs Index: configure.in =================================================================== RCS file: /cvsroot/robotflow/RobotFlow/configure.in,v retrieving revision 1.42 retrieving revision 1.43 diff -C2 -d -r1.42 -r1.43 *** configure.in 25 Jun 2004 17:02:08 -0000 1.42 --- configure.in 22 Jul 2004 20:59:26 -0000 1.43 *************** *** 156,186 **** AC_MSG_RESULT("MARIE disabled by user") else ! dnl Test for ACE (Yannick Brosseau & Dominic Letourneau) ! AC_MSG_CHECKING(for ACE) ! ACE_FOUND="" ! ! AC_ARG_WITH(ACE, [ --with-ACE Where ACE is installed (/usr/local)], ACE_DIR="$withval") ! ! dnl test which ACE_DIR, std way ! if test -n "$ACE_DIR"; then ! ACE_LIBS="-L$ACE_DIR/lib -lACE" ! ACE_INCLUDES="-I$ACE_DIR/include" ! AC_MSG_RESULT("found ACE_wrappers in $ACE_DIR") ! ACE_FOUND="yes" ! fi ! ! dnl test with ACE_ROOT ! if test -z "$ACE_FOUND" && test -n "$ACE_ROOT"; then ! dnl Now attempting in a ACE_wrappers style. ! AC_MSG_RESULT("found ACE_wrappers in $ACE_ROOT") ! ACE_LIBS="-L$ACE_ROOT/ace -lACE" ! ACE_INCLUDES="-I$ACE_ROOT" ! ACE_FOUND="yes" ! fi AC_ARG_WITH(MARIE, [ --with-MARIE Where MARIE is installed (/usr/local)], MARIE_DIR="$withval") dnl Test for MARIE (Dominic Letourneau) ! if test -n "$ACE_FOUND" && test -n "$MARIE_DIR"; then AC_MSG_RESULT("Using MARIE in $MARIE_DIR") MARIE_LIBS="-L$MARIE_DIR/lib -lmariedata -lmariecommon" --- 156,187 ---- AC_MSG_RESULT("MARIE disabled by user") else ! # dnl Test for ACE (Yannick Brosseau & Dominic Letourneau) ! # AC_MSG_CHECKING(for ACE) ! # ACE_FOUND="" ! # ! # AC_ARG_WITH(ACE, [ --with-ACE Where ACE is installed (/usr/local)], ACE_DIR="$withval") ! # ! # dnl test which ACE_DIR, std way ! # if test -n "$ACE_DIR"; then ! # ACE_LIBS="-L$ACE_DIR/lib -lACE" ! # ACE_INCLUDES="-I$ACE_DIR/include" ! # AC_MSG_RESULT("found ACE_wrappers in $ACE_DIR") ! # ACE_FOUND="yes" ! # fi ! # ! # dnl test with ACE_ROOT ! # if test -z "$ACE_FOUND" && test -n "$ACE_ROOT"; then ! # dnl Now attempting in a ACE_wrappers style. ! # AC_MSG_RESULT("found ACE_wrappers in $ACE_ROOT") ! # ACE_LIBS="-L$ACE_ROOT/ace -lACE" ! # ACE_INCLUDES="-I$ACE_ROOT" ! # ACE_FOUND="yes" ! # fi + AC_ARG_WITH(MARIE, [ --with-MARIE Where MARIE is installed (/usr/local)], MARIE_DIR="$withval") dnl Test for MARIE (Dominic Letourneau) ! if test -n "$MARIE_DIR"; then AC_MSG_RESULT("Using MARIE in $MARIE_DIR") MARIE_LIBS="-L$MARIE_DIR/lib -lmariedata -lmariecommon" *************** *** 189,195 **** else AC_PATH_PROG(MARIE_CONFIG,marie-config,no,$PATH:$prefix/bin:$prefix/marie/bin) ! if test "$MARIE_CONFIG" != no && test -n "$ACE_FOUND"; then ! MARIE_LIBS=`$MARIE_CONFIG --libs libmariedata libmariecommon` ! MARIE_INCLUDES=`$MARIE_CONFIG --cflags libmariedata libmariecommon` MARIE_FOUND="yes" else --- 190,196 ---- else AC_PATH_PROG(MARIE_CONFIG,marie-config,no,$PATH:$prefix/bin:$prefix/marie/bin) ! if test "$MARIE_CONFIG" != no; then ! MARIE_LIBS=`$MARIE_CONFIG --libs libmariedata` ! MARIE_INCLUDES=`$MARIE_CONFIG --cflags libmariedata` MARIE_FOUND="yes" else |
From: Carle C. <car...@us...> - 2004-07-22 20:59:43
|
Update of /cvsroot/robotflow/RobotFlow/Player/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28909/Player/src Modified Files: Makefile.am Log Message: Remove ACEXML lib dependencies, correct minor bugs Index: Makefile.am =================================================================== RCS file: /cvsroot/robotflow/RobotFlow/Player/src/Makefile.am,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Makefile.am 31 May 2004 20:15:34 -0000 1.7 --- Makefile.am 22 Jul 2004 20:59:27 -0000 1.8 *************** *** 17,21 **** PlayerGripper.cc ! libPlayerDevices_la_LDFLAGS = -release $(LT_RELEASE) $(PLAYER_LIBS) $(OVERFLOW_LIBS) INCLUDES = -I../include $(OVERFLOW_INCLUDE) \ --- 17,21 ---- PlayerGripper.cc ! libPlayerDevices_la_LDFLAGS = -release $(LT_RELEASE) $(PLAYER_LIBS) $(OVERFLOW_LIB) INCLUDES = -I../include $(OVERFLOW_INCLUDE) \ |
From: Carle C. <car...@us...> - 2004-07-22 20:59:43
|
Update of /cvsroot/robotflow/RobotFlow/MARIE/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28909/MARIE/src Modified Files: Makefile.am Log Message: Remove ACEXML lib dependencies, correct minor bugs Index: Makefile.am =================================================================== RCS file: /cvsroot/robotflow/RobotFlow/MARIE/src/Makefile.am,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Makefile.am 14 Jun 2004 18:58:54 -0000 1.8 --- Makefile.am 22 Jul 2004 20:59:26 -0000 1.9 *************** *** 3,7 **** #AUTOMAKE_OPTIONS = no-dependencies ! INCLUDES = $(ACE_INCLUDES) $(OVERFLOW_INCLUDE) $(MARIE_INCLUDES) -I../include -I../../Behaviors/include lib_LTLIBRARIES = libRFMarie.la --- 3,8 ---- #AUTOMAKE_OPTIONS = no-dependencies ! INCLUDES = $(OVERFLOW_INCLUDE) $(MARIE_INCLUDES) $(XML2_INCLUDE) \ ! -I../include -I../../Behaviors/include lib_LTLIBRARIES = libRFMarie.la *************** *** 19,23 **** MarieCommandBehavior.cpp \ MarieCommandCamera.cpp \ ! MarieCommandMotor.cpp install-data-local: --- 20,25 ---- MarieCommandBehavior.cpp \ MarieCommandCamera.cpp \ ! MarieCommandMotor.cpp \ ! MarieDataRaw.cpp install-data-local: *************** *** 28,32 **** ! libRFMarie_la_LDFLAGS = -release $(LT_RELEASE) $(ACE_LIBS) $(FLOWDESIGNER_LIB) \ $(XML2_LIB) $(MARIE_LIBS) --- 30,34 ---- ! libRFMarie_la_LDFLAGS = -release $(LT_RELEASE) $(OVERFLOW_LIB) \ $(XML2_LIB) $(MARIE_LIBS) |
From: Carle C. <car...@us...> - 2004-07-22 20:59:43
|
Update of /cvsroot/robotflow/RobotFlow/MARIE/include In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv28909/MARIE/include Modified Files: Makefile.am Log Message: Remove ACEXML lib dependencies, correct minor bugs Index: Makefile.am =================================================================== RCS file: /cvsroot/robotflow/RobotFlow/MARIE/include/Makefile.am,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** Makefile.am 14 Jun 2004 18:36:35 -0000 1.5 --- Makefile.am 22 Jul 2004 20:59:26 -0000 1.6 *************** *** 14,18 **** MariePull.h \ MariePeek.h \ ! MariePush.h --- 14,19 ---- MariePull.h \ MariePeek.h \ ! MariePush.h \ ! MarieDataRaw.h |
From: Dominic L. <ma...@us...> - 2004-07-01 18:43:27
|
Update of /cvsroot/robotflow/RobotFlow/html In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22794 Modified Files: home.html Log Message: Fixed colors to fit with RobotFlow design. Index: home.html =================================================================== RCS file: /cvsroot/robotflow/RobotFlow/html/home.html,v retrieving revision 1.26 retrieving revision 1.27 diff -C2 -d -r1.26 -r1.27 *** home.html 1 Jul 2004 18:34:47 -0000 1.26 --- home.html 1 Jul 2004 18:43:18 -0000 1.27 *************** *** 29,35 **** <h1>LATEST NEWS</h1> ! <table width="100%" bgcolor="#CCDDEE"> ! <td width="20%" bgcolor="#AABBCC"><div align="left"><b>DATE</b></div></td> ! <td width="80%" bgcolor="#AABBCC"><div align=left><b>DESCRIPTION</b></div></td> <tr> --- 29,35 ---- <h1>LATEST NEWS</h1> ! <table width="100%" bgcolor="#FFFF11"> ! <td width="20%" bgcolor="#CCCC50"><div align="left"><b>DATE</b></div></td> ! <td width="80%" bgcolor="#CCCC50"><div align=left><b>DESCRIPTION</b></div></td> <tr> |
From: Dominic L. <ma...@us...> - 2004-07-01 18:40:48
|
Update of /cvsroot/robotflow/RobotFlow/html In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv22284 Modified Files: status.html Log Message: Status updated. Index: status.html =================================================================== RCS file: /cvsroot/robotflow/RobotFlow/html/status.html,v retrieving revision 1.3 retrieving revision 1.4 diff -C2 -d -r1.3 -r1.4 *** status.html 7 Apr 2004 12:41:54 -0000 1.3 --- status.html 1 Jul 2004 18:40:39 -0000 1.4 *************** *** 42,49 **** <tr> <td width="30%"><b>Integration with MARIE</b></b></td> ! <td width="10%">01/04/2004</td> ! <td width="10%">PARTIALLY COMPLETED</td> <td width="50%"><a href="http://marie.sourceforge.net">MARIE</a> is the Mobile & Autonomous Robotics Integration Environment. ! Definition of the "unified" project that will demonstrates the capabilities of both <a href="http://marie.sourceforge.net">MARIE</a> / <a href="http://flowdesigner.sourceforge.net">FlowDesigner</a> / RobotFlow</td> </tr> <tr> --- 42,49 ---- <tr> <td width="30%"><b>Integration with MARIE</b></b></td> ! <td width="10%">01/07/2004</td> ! <td width="10%">COMPLETED</td> <td width="50%"><a href="http://marie.sourceforge.net">MARIE</a> is the Mobile & Autonomous Robotics Integration Environment. ! Creation of the "Showcase" project that will demonstrate the capabilities of both <a href="http://marie.sourceforge.net">MARIE</a> / <a href="http://flowdesigner.sourceforge.net">FlowDesigner</a> / RobotFlow</td> </tr> <tr> |
From: Dominic L. <ma...@us...> - 2004-07-01 18:34:56
|
Update of /cvsroot/robotflow/RobotFlow/html In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv21113 Modified Files: home.html Log Message: Fixed my name! Index: home.html =================================================================== RCS file: /cvsroot/robotflow/RobotFlow/html/home.html,v retrieving revision 1.25 retrieving revision 1.26 diff -C2 -d -r1.25 -r1.26 *** home.html 1 Jul 2004 18:32:24 -0000 1.25 --- home.html 1 Jul 2004 18:34:47 -0000 1.26 *************** *** 112,116 **** <tr> <td> <div align=left><a href="http://sourceforge.net"><img SRC="http://sourceforge.net/sflogo.php?group_id=51402&type=5" ALT="SourceForge Logo" BORDER=0 height=62 width=210></a></div></td> ! <td> <div align=right> Please contact <a HREF="mailto:dom...@us...">Dominic L�ourneau</a> for more information.</div></td> </tr> </table> --- 112,116 ---- <tr> <td> <div align=left><a href="http://sourceforge.net"><img SRC="http://sourceforge.net/sflogo.php?group_id=51402&type=5" ALT="SourceForge Logo" BORDER=0 height=62 width=210></a></div></td> ! <td> <div align=right> Please contact <a HREF="mailto:dom...@us...">Dominic Létourneau</a> for more information.</div></td> </tr> </table> |
From: Dominic L. <ma...@us...> - 2004-07-01 18:32:33
|
Update of /cvsroot/robotflow/RobotFlow/html In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20726 Modified Files: home.html Log Message: Added colored news. MARIE showcase now available. Index: home.html =================================================================== RCS file: /cvsroot/robotflow/RobotFlow/html/home.html,v retrieving revision 1.24 retrieving revision 1.25 diff -C2 -d -r1.24 -r1.25 *** home.html 28 Jun 2004 01:48:45 -0000 1.24 --- home.html 1 Jul 2004 18:32:24 -0000 1.25 *************** *** 29,33 **** <h1>LATEST NEWS</h1> ! <table width="100%"> <tr> <td width="15%"> <div align=left>25/06/2004</div></td> --- 29,36 ---- <h1>LATEST NEWS</h1> ! <table width="100%" bgcolor="#CCDDEE"> ! <td width="20%" bgcolor="#AABBCC"><div align="left"><b>DATE</b></div></td> ! <td width="80%" bgcolor="#AABBCC"><div align=left><b>DESCRIPTION</b></div></td> ! <tr> <td width="15%"> <div align=left>25/06/2004</div></td> *************** *** 36,40 **** that are able to extract, serialize and unserialize MARIE data objects. MARIE must be compiled before RobotFlow in order to use MARIE blocks. If you don't want to use MARIE blocks, use --disable-MARIE. RobotFlow is now part of the MARIE showcase ! that will be available shortly.Enjoy!</div></td> </tr> <tr> --- 39,43 ---- that are able to extract, serialize and unserialize MARIE data objects. MARIE must be compiled before RobotFlow in order to use MARIE blocks. If you don't want to use MARIE blocks, use --disable-MARIE. RobotFlow is now part of the MARIE showcase ! that is available at MARIE's project web site. Enjoy!</div></td> </tr> <tr> |