From: Pierre M. <sid...@us...> - 2005-05-26 19:45:22
|
Update of /cvsroot/robotflow/RobotFlow/Vision/src In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv6687 Modified Files: VisualROI.cc VisualTargetManager.cc Log Message: Now using RCPtr to produce reference output instead of copying member data. Index: VisualTargetManager.cc =================================================================== RCS file: /cvsroot/robotflow/RobotFlow/Vision/src/VisualTargetManager.cc,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** VisualTargetManager.cc 12 Apr 2005 19:58:10 -0000 1.4 --- VisualTargetManager.cc 26 May 2005 19:45:09 -0000 1.5 *************** *** 125,129 **** // VisualTargetManager::VisualTargetManager() - : m_target(NULL) { --- 125,128 ---- *************** *** 134,139 **** // VisualTargetManager::VisualTargetManager(std::string nodeName, ParameterSet params) ! : BufferedNode(nodeName, params), ! m_target(NULL) { m_imageInID = addInput("IMAGE_IN"); --- 133,137 ---- // VisualTargetManager::VisualTargetManager(std::string nodeName, ParameterSet params) ! : BufferedNode(nodeName, params) { m_imageInID = addInput("IMAGE_IN"); *************** *** 171,176 **** m_curImage = cvCreateImage(imgSize, IPL_DEPTH_8U, m_numChannels); ! m_target = new VisualTarget<double>(); ! m_refTarget = RCPtr<VisualTarget<double> >(m_target); m_roiColor[0] = 255; --- 169,173 ---- m_curImage = cvCreateImage(imgSize, IPL_DEPTH_8U, m_numChannels); ! m_refTarget = RCPtr<VisualTarget<double> >(new VisualTarget<double>()); m_roiColor[0] = 255; *************** *** 181,185 **** VisualTargetManager::~VisualTargetManager() { - delete m_target; cvReleaseImage(&m_curImage); } --- 178,181 ---- *************** *** 261,265 **** try { if (output_id == m_imageOutID) { - fflush(stdout); // Get current image RCPtr<Image> imageRef = getInput(m_imageInID, count); --- 257,260 ---- *************** *** 274,280 **** memcpy(m_curImage->imageData, imageRef->get_data(), m_numBytesInFrame); ! if (m_target->IsValid()) { // Draw current target's ROI in current image ! m_target->GetCstROI()->DrawROI(m_curImage, (const unsigned char *)m_roiColor); // Copy current image for output --- 269,275 ---- memcpy(m_curImage->imageData, imageRef->get_data(), m_numBytesInFrame); ! if (m_refTarget->IsValid()) { // Draw current target's ROI in current image ! m_refTarget->GetCstROI()->DrawROI(m_curImage, (const unsigned char *)m_roiColor); // Copy current image for output *************** *** 300,311 **** } else if (output_id == m_roiOutID) { ! if (m_target->IsValid()) { // Output directly the reference since it should // only be used as a constant reference ! //VisualROI *outROI = new VisualROI(*(m_target->GetCstROI())); ! //(*outputs[m_roiOutID].buffer)[count] = ObjectRef(outROI); ! //(*outputs[m_roiOutID].buffer)[count] = ObjectRef(RCPtr<VisualROI>(m_target->GetROI())); ! static RCPtr<VisualROI> refROI = RCPtr<VisualROI>(m_target->GetROI()); ! (*outputs[m_roiOutID].buffer)[count] = refROI; } else { --- 295,302 ---- } else if (output_id == m_roiOutID) { ! if (m_refTarget->IsValid()) { // Output directly the reference since it should // only be used as a constant reference ! (*outputs[m_roiOutID].buffer)[count] = m_refTarget->GetROIRCPtr(); } else { *************** *** 315,324 **** } else if (output_id == m_targetOutID) { ! if (m_target->IsValid()) { // Output directly the reference since it should // only be used as a constant reference - //VisualTarget<double> *outTarget = new VisualTarget<double>(*m_target); - //(*outputs[m_targetOutID].buffer)[count] = ObjectRef(outTarget); - static RCPtr<VisualTarget<double> > refTarget = RCPtr<VisualTarget<double> >(m_target); (*outputs[m_targetOutID].buffer)[count] = m_refTarget; } --- 306,312 ---- } else if (output_id == m_targetOutID) { ! if (m_refTarget->IsValid()) { // Output directly the reference since it should // only be used as a constant reference (*outputs[m_targetOutID].buffer)[count] = m_refTarget; } *************** *** 329,339 **** } else if (output_id == m_targetProbOutID) { ! if (m_target->GetCurrentAge() < -10) { // Target is too old to track // Invalidate it ! m_target->SetValidity(false); } ! if (!m_target->IsValid()) { // Try to initialize a new target // Get detected ROI --- 317,327 ---- } else if (output_id == m_targetProbOutID) { ! if (m_refTarget->GetCurrentAge() < -10) { // Target is too old to track // Invalidate it ! m_refTarget->SetValidity(false); } ! if (!m_refTarget->IsValid()) { // Try to initialize a new target // Get detected ROI *************** *** 343,348 **** if (!roiRef->isNil()) { // Initialize target at current ROI ! m_target->SetROI(&(object_cast<VisualROI>(roiRef))); ! m_target->SetValidity(true); if (!m_ppCompleted) { --- 331,336 ---- if (!roiRef->isNil()) { // Initialize target at current ROI ! m_refTarget->SetROI(&(object_cast<VisualROI>(roiRef))); ! m_refTarget->SetValidity(true); if (!m_ppCompleted) { *************** *** 354,369 **** // Get features for current ROI and use them // as the target feature model ! ObjectRef featVecRef = getInput(m_featVecInID, count); ! if (featVecRef->isNil()) { throw new GeneralException ("VisualTargetManager::calculate : cannot initialize target with null input FEATURES_VECTOR.",__FILE__,__LINE__); } ! ! m_target->SetDescriptorsVec(&(object_cast<Vector<VisualFeatureDesc<double> *> >(featVecRef))); ! m_target->InitCueWeights(); ! m_target->InitAges(); } } ! if (m_target->IsValid()) { double sim = 0.0; bool targetMatch = false; --- 342,357 ---- // Get features for current ROI and use them // as the target feature model ! ObjectRef featVecObjRef = getInput(m_featVecInID, count); ! if (featVecObjRef->isNil()) { throw new GeneralException ("VisualTargetManager::calculate : cannot initialize target with null input FEATURES_VECTOR.",__FILE__,__LINE__); } ! RCPtr<Vector<VisualFeatureDesc<double> *> > featVecRef = featVecObjRef; ! m_refTarget->SetDescriptorsVec(&(*featVecRef)); ! m_refTarget->InitCueWeights(); ! m_refTarget->InitAges(); } } ! if (m_refTarget->IsValid()) { double sim = 0.0; bool targetMatch = false; *************** *** 382,386 **** if (!targetRef->isNil()) { ! *m_target = object_cast<VisualTarget<double> >(targetRef); // Get features to evalute the likelihood of the current --- 370,374 ---- if (!targetRef->isNil()) { ! *m_refTarget = object_cast<VisualTarget<double> >(targetRef); // Get features to evalute the likelihood of the current *************** *** 391,395 **** } ! sim = m_target->SimilarityWCueAdapt( &(object_cast<Vector<VisualFeatureDesc<double> *> >(featVecRef)), m_cueAdaptRate); --- 379,383 ---- } ! sim = m_refTarget->SimilarityWCueAdapt( &(object_cast<Vector<VisualFeatureDesc<double> *> >(featVecRef)), m_cueAdaptRate); *************** *** 397,403 **** targetMatch = (sim >= m_targetMatchThres); ! m_target->AgeTarget(targetMatch); if (sim > m_targetAdaptThres) { ! m_target->Adapt(&(object_cast<Vector<VisualFeatureDesc<double> *> >(featVecRef)), m_targetAdaptRate); } --- 385,391 ---- targetMatch = (sim >= m_targetMatchThres); ! m_refTarget->AgeTarget(targetMatch); if (sim > m_targetAdaptThres) { ! m_refTarget->Adapt(&(object_cast<Vector<VisualFeatureDesc<double> *> >(featVecRef)), m_targetAdaptRate); } *************** *** 419,424 **** } else if (output_id == m_targetDXOutID) { ! if (m_target->IsValid()) { ! float deltaX = (float)(m_target->GetCstROI()->GetXCen()) - m_imgXCen; (*outputs[m_targetDXOutID].buffer)[count] = ObjectRef(Float::alloc(deltaX)); } --- 407,412 ---- } else if (output_id == m_targetDXOutID) { ! if (m_refTarget->IsValid()) { ! float deltaX = (float)(m_refTarget->GetCstROI()->GetXCen()) - m_imgXCen; (*outputs[m_targetDXOutID].buffer)[count] = ObjectRef(Float::alloc(deltaX)); } *************** *** 428,433 **** } else if (output_id == m_targetDYOutID) { ! if (m_target->IsValid()) { ! float deltaY = m_imgYCen - (float)(m_target->GetCstROI()->GetYCen()); (*outputs[m_targetDYOutID].buffer)[count] = ObjectRef(Float::alloc(deltaY)); } --- 416,421 ---- } else if (output_id == m_targetDYOutID) { ! if (m_refTarget->IsValid()) { ! float deltaY = m_imgYCen - (float)(m_refTarget->GetCstROI()->GetYCen()); (*outputs[m_targetDYOutID].buffer)[count] = ObjectRef(Float::alloc(deltaY)); } Index: VisualROI.cc =================================================================== RCS file: /cvsroot/robotflow/RobotFlow/Vision/src/VisualROI.cc,v retrieving revision 1.4 retrieving revision 1.5 diff -C2 -d -r1.4 -r1.5 *** VisualROI.cc 12 Apr 2005 19:58:10 -0000 1.4 --- VisualROI.cc 26 May 2005 19:45:09 -0000 1.5 *************** *** 163,166 **** --- 163,226 ---- } + void VisualROI::DrawROI(int i_width, int i_height, int i_numChannels, + unsigned char *io_pixels, const unsigned char *i_color) const + { + if (!io_pixels) { + throw new GeneralException ("VisualROI::DrawROI : invalid pixels reference.",__FILE__,__LINE__); + } + + if (!i_color) { + throw new GeneralException ("VisualROI::DrawROI : invalid color reference.",__FILE__,__LINE__); + } + + if (!m_perim) { + throw new GeneralException ("VisualROI::DrawROI : cannot draw ROI with uninitialized region data.",__FILE__,__LINE__); + } + + unsigned char *p_pixels = io_pixels; + const short *p_perim = this->GetCstPerim(); + int imgWidth = i_width; + int imgHeight = i_height; + int numChannels = i_numChannels; + int i, c, x, y; + short deltaX, deltaY; + bool broken = true; + + // Start at the top center of the region + x = m_xCen; + y = m_yCen; + p_pixels += numChannels*(y*imgWidth + x); + + // Overlay region of interest + for (i=m_perimLength; i>0; i--) { + deltaX = *p_perim++; + deltaY = *p_perim++; + x += deltaX; + y += deltaY; + + // Draw only if region is visible + if (y>0 && y<imgHeight && x>0 && x<imgWidth) { + if (!broken) { + // Relative position + p_pixels += numChannels*(deltaY*imgWidth + deltaX); + } + else { + // Absolute position + p_pixels = (unsigned char *)(io_pixels + numChannels*(y*imgWidth + x)); + broken = false; + } + + for (c=0; c<numChannels; c++) { + *p_pixels++ = i_color[c]; + } + + p_pixels -= numChannels; + } + else { + broken = true; + } + } + } + void VisualROI::Reset(int i_hsX, int i_hsY, int i_angle) { *************** *** 259,262 **** --- 319,327 ---- } + void VisualROI::SetType(e_VISUALROI_type i_type) + { + m_type = i_type; + } + void VisualROI::SetXCen(int i_xCen) { |