//-----------------------------------------------. void guiTypeTextDropDown::updateGui(float x, float y, bool firstHit, bool isRelative) { if( value.getNumValues() == 0 ){ return; } if(!firstHit)return; if( state == SG_STATE_SELECTED){ float relX = x - hitArea.x; float relY = y - hitArea.y; if(bShowDropDown) { for(unsigned int i = 0; i < vecDropList.size(); i++){ ofRectangle tmpRect(0, i * (boxHeight), boundingBox.width, boxHeight); if( isInsideRect(relX, relY, tmpRect) ){ value.setValue(i, 0); bShowDropDown = false; //CB notify(); break; } } } else { ofRectangle tmpRect(0, 0, boundingBox.width, boxHeight); if( isInsideRect(relX, relY, tmpRect) ){ bShowDropDown = true; } } } }
int CBUtils::getuiClearRegion(hwc_display_contents_1_t* list, hwc_rect_t &clearWormholeRect, LayerProp *layerProp) { size_t last = list->numHwLayers - 1; hwc_rect_t fbFrame = list->hwLayers[last].displayFrame; Rect fbFrameRect(fbFrame.left,fbFrame.top,fbFrame.right,fbFrame.bottom); Region wormholeRegion(fbFrameRect); if(cb_swap_rect::getInstance().checkSwapRectFeature_on() == true){ wormholeRegion.set(0,0); for(size_t i = 0 ; i < last; i++) { if(((list->hwLayers[i].blending == HWC_BLENDING_NONE) && (list->hwLayers[i].planeAlpha == 0xFF)) || !(layerProp[i].mFlags & HWC_COPYBIT) || (list->hwLayers[i].flags & HWC_SKIP_HWC_COMPOSITION)) continue ; hwc_rect_t displayFrame = list->hwLayers[i].displayFrame; Rect tmpRect(displayFrame.left,displayFrame.top, displayFrame.right,displayFrame.bottom); wormholeRegion.set(tmpRect); } }else{ for (size_t i = 0 ; i < last; i++) { // need to take care only in per pixel blending. // Restrict calculation only for copybit layers. if((list->hwLayers[i].blending != HWC_BLENDING_NONE) || (list->hwLayers[i].planeAlpha != 0xFF) || !(layerProp[i].mFlags & HWC_COPYBIT)) continue ; hwc_rect_t displayFrame = list->hwLayers[i].displayFrame; Rect tmpRect(displayFrame.left,displayFrame.top,displayFrame.right, displayFrame.bottom); Region tmpRegion(tmpRect); wormholeRegion.subtractSelf(wormholeRegion.intersect(tmpRegion)); } } if(wormholeRegion.isEmpty()){ return 0; } //TO DO :- 1. remove union and call clear for each rect. Region::const_iterator it = wormholeRegion.begin(); Region::const_iterator const end = wormholeRegion.end(); while (it != end) { const Rect& r = *it++; hwc_rect_t tmpWormRect = {r.left,r.top,r.right,r.bottom}; int dst_w = clearWormholeRect.right - clearWormholeRect.left; int dst_h = clearWormholeRect.bottom - clearWormholeRect.top; if (!(dst_w || dst_h)) clearWormholeRect = tmpWormRect; else getUnion(clearWormholeRect, tmpWormRect, clearWormholeRect); } return 1; }
void Console::selectEntities() { Entity* tmp = 0; for(int i=0; i < TF::world->entities.size(); i++) { tmp = TF::world->entities[i]; Rectangle tmpRect(startPoint->x, startPoint->y, endPoint->x - startPoint->x, endPoint->y - startPoint->y); Rectangle rect; rect.x = tmpRect.x; rect.y = tmpRect.y; rect.width = fabs(tmpRect.width); rect.height = fabs(tmpRect.height); if(tmpRect.width < 0) rect.x = endPoint->x; if(tmpRect.height < 0) rect.y = endPoint->y; if( (tmp->x >= rect.x && tmp->x <= (rect.x + rect.width)) && (tmp->y >= rect.y && tmp->y <= (rect.y + rect.height)) ) { selectedEntities.push_back(tmp); } } }
/** * generate negative sample patches by randomly sampling from the frame * Arguments: * videoFrame: the video frame from which the samples are generated */ void SVMPlayerDetector::getNonPlayerPatches(cv::Mat videoFrame) { /// prepare the same number of samples int numSamples = this->m_playerPatchVect.size(); // generate random image patches int frameWidth = videoFrame.size().width; int frameHeight = videoFrame.size().height; // range for the samples int xMin = m_bbSize.width; int xMax = frameWidth - m_bbSize.width; int yMin = m_bbSize.height; int yMax = frameHeight - m_bbSize.height; for(int i = 0; i < numSamples; i++) { // generate random position // generate x in the range ( m_bbSize.width/2 + 1, frameWidth - m_bbSize.width/2 - 1) int randX = rand() % (xMax - xMin); randX += xMin; int randY = rand() % (yMax - yMin); randY += yMin; // extract the patch cv::Rect tmpRect(randX,randY,m_bbSize.width,m_bbSize.height); cv::Mat tmpPatch = videoFrame(tmpRect); // save to the non-player patch list this->m_nonPlayerPatchVect.push_back(tmpPatch); /// visualize the patches for verification purpose cv::namedWindow("negbb"); cv::imshow("negbb",tmpPatch); cv::waitKey(30); } }
IPlugText::IPlugText(IPlugInstanceInfo instanceInfo) : IPLUG_CTOR(kNumParams, kNumPrograms, instanceInfo), mGain(1.) { TRACE; //arguments are: name, defaultVal, minVal, maxVal, step, label GetParam(kGain)->InitDouble("Gain", 50., 0., 100.0, 0.01, "%"); GetParam(kGain)->SetShape(2.); IGraphics* pGraphics = MakeGraphics(this, kWidth, kHeight); pGraphics->AttachPanelBackground(&COLOR_GRAY); IRECT tmpRect(10, 10, 200, 30); IText textProps(12, &COLOR_BLACK, "Arial", IText::kStyleNormal, IText::kAlignCenter, 0, IText::kQualityDefault); pGraphics->AttachControl(new ITextControl(this, tmpRect, &textProps, "hello iplug!")); IRECT tmpRect2(30, 30, 200, 60); IText textProps2(18, &COLOR_WHITE, "Tahoma", IText::kStyleNormal, IText::kAlignCenter, 0, IText::kQualityDefault); pGraphics->AttachControl(new ITextControl(this, tmpRect2, &textProps2, "hello iplug!")); IRECT tmpRect3(80, 50, 200, 80.); IText textProps3(24, &COLOR_RED, "Arial", IText::kStyleItalic, IText::kAlignFar, 0, IText::kQualityDefault); pGraphics->AttachControl(new ITextControl(this, tmpRect3, &textProps3, "hello iplug!")); IRECT tmpRect4(120, 60, 300, 120); IText textProps4(40, &COLOR_ORANGE, "Arial", IText::kStyleNormal, IText::kAlignCenter, 0, IText::kQualityDefault); pGraphics->AttachControl(new ITextControl(this, tmpRect4, &textProps4, "hello iplug!")); IRECT tmpRect5(10, 100, 400, 170); IText textProps5(50, &COLOR_BLUE, "Courier", IText::kStyleNormal, IText::kAlignCenter, 0, IText::kQualityDefault); pGraphics->MeasureIText(&textProps5, "hello iplug!", &tmpRect5); // get the bounds of the text and stick them in tmpRect5 pGraphics->AttachControl( new IPanelControl(this, tmpRect5, &COLOR_WHITE)); tmpRect5 = IRECT(10, 100, 400, 170); pGraphics->AttachControl(new ITextControl(this, tmpRect5, &textProps5, "hello iplug!")); DBGMSG("text bounds = %i, %i, %i, %i\n", tmpRect5.L, tmpRect5.T, tmpRect5.R, tmpRect5.B); IBitmap blackText = pGraphics->LoadIBitmap(TEXT_BLACK_ID, TEXT_BLACK_FN, 95, true); IBitmap whiteText = pGraphics->LoadIBitmap(TEXT_WHITE_ID, TEXT_WHITE_FN, 95, true); IRECT tmpRect6(10, 250, 400, 170); pGraphics->AttachControl(new IBitmapTextControl(this, tmpRect6, &blackText, "i'm bitmap monospace text")); IRECT tmpRect7(10, 280, 400, 170); pGraphics->AttachControl(new IBitmapTextControl(this, tmpRect7, &whiteText, "i'm also bitmap monospace text")); AttachGraphics(pGraphics); //MakePreset("preset 1", ... ); MakeDefaultPreset((char *) "-", kNumPrograms); }
void SpriteRenderer::RenderSprite() { if (!_sprite || !_gameobject->IsEnabled()) { return; } // calculate the position to screen Vector pos = _gameobject->GetGlobalPosition() - sCamera->GetGlobalPosition(); pos.x -= _pivotX; pos.y -= _pivotY; Rect tmpRect(_rect); tmpRect._down = _rect._down - _rect._up; tmpRect._right = _rect._right - _rect._left; sRenderer->RenderRectSprite(pos, tmpRect, _sprite, _reverse); }
//-----------------------------------------------. void guiTypeMultiToggle::updateGui(float x, float y, bool firstHit, bool isRelative){ if(!firstHit)return; if( state == SG_STATE_SELECTED){ float relX = x - hitArea.x; float relY = y - hitArea.y; for(unsigned int i = 0; i < bNames.size(); i++){ ofRectangle tmpRect(0, i * (boxSize+boxSpacing), boxSize, boxSize); if( isInsideRect(relX, relY, tmpRect) ){ value.setValue(i, 0); break; } } //CB notify(); } }
/** * get the bound box based on the mass center computed from Partical Filter algorithm * Arguments: * videoFrame: current frame * massCenter: center of the particles */ void SVMPlayerDetector::getBBFromMassCenter(cv::Mat videoFrame,cv::Point massCenter) { int leftPos = massCenter.x - this->m_bbSize.width / 2; int topPos = massCenter.y - this->m_bbSize.height / 2; /// judge whether current bound box exceeds the frame border if( leftPos <0 || topPos < 0 || leftPos + m_bbSize.width >= videoFrame.size().width || topPos + m_bbSize.height >= videoFrame.size().height ) { return; } this->m_patchFrame = videoFrame.clone(); // assign to tmpRect // get the top-left corner of the bound box from massCenter cv::Rect tmpRect(leftPos, topPos, m_bbSize.width, m_bbSize.height); // add to the bounding box vector this->m_bbVect.push_back(tmpRect); // get a patch from current frame for tmpRect cv::Mat tmpPatch = m_patchFrame(tmpRect); // cv::rectangle(videoFrame,tmpRect,cv::Scalar(255,255,255),1); this->m_playerPatchVect.push_back(tmpPatch); this->m_bbPatch = tmpPatch; }
void CFolderHostLevels::DrawFrame(HSURFACE hDestSurf, LTRect *rect, LTBOOL bSel) { int xo = g_pInterfaceResMgr->GetXOffset(); int yo = g_pInterfaceResMgr->GetYOffset(); HLTCOLOR hColor = (bSel ? m_hSelectedColor : m_hNonSelectedColor); LTRect tmpRect(xo+rect->left, yo+rect->top+nBarHeight, xo+rect->right, yo+rect->top+nBarHeight+2); g_pLTClient->FillRect(hDestSurf,&tmpRect,hColor); tmpRect.bottom = yo+rect->bottom; tmpRect.top = tmpRect.bottom - 2; g_pLTClient->FillRect(hDestSurf,&tmpRect,hColor); tmpRect = LTRect(xo+rect->left, yo+rect->top+nBarHeight+2, xo+rect->left+2, yo+rect->bottom-2); g_pLTClient->FillRect(hDestSurf,&tmpRect,hColor); tmpRect.right = xo+rect->right; tmpRect.left = tmpRect.right - 2; g_pLTClient->FillRect(hDestSurf,&tmpRect,hColor); }
void worker::doWork() { qreal width = m_scene->sceneRect().width(); qreal height = m_scene->sceneRect().height(); QPointF topLeft = m_scene->sceneRect().topLeft(); int horizontalCount = int(width / 5); int verticalCount = int(height / 10); QPen pen(Qt::red); QSizeF size(5,10); for (int i=0;i<horizontalCount;i++) { topLeft.setX(topLeft.x() + i*5); qDebug() << "i: " << i; for (int j=0;j<verticalCount;j++) { topLeft.setY(topLeft.y() + j*10); qDebug() << "j: " << j; QRectF tmpRect(topLeft,size); m_scene->addRect(tmpRect,pen); } } }
void DispWidget::arrangeSpots() { qreal width = sceneRect().width(); qreal height = sceneRect().height(); QPointF topLeft = sceneRect().topLeft(); int horizontalCount = int(width / 5); int verticalCount = int(height / 10); QPen pen(Qt::red); // QBrush brush(Qt::red,Qt::SolidPattern); QSizeF size(5,10); QPointF tmpTopLeft = sceneRect().topLeft(); // qreal x,y,startX,startY; // startX = topLeft.x(); // startY = topLeft.y(); for (int i=0;i<horizontalCount;i++) { tmpTopLeft.setX(topLeft.x() + i*5); // x = startX + i*5; qDebug() << "i: " << i; for (int j=0;j<verticalCount;j++) { tmpTopLeft.setY(topLeft.y() + j*10); // y = startY + j*5; qDebug() << "j: " << j; QRectF tmpRect(tmpTopLeft,size); // QRectF tmpRect(x,y,5,10); if (currPath.contains(tmpRect.center())) { addRect(tmpRect,pen); m_spots << tmpRect; } } } }
void clAuiDockArt::DrawCaption(wxDC& dc, wxWindow* window, const wxString& text, const wxRect& rect, wxAuiPaneInfo& pane) { wxRect tmpRect(wxPoint(0, 0), rect.GetSize()); // Hackishly prevent assertions on linux if(tmpRect.GetHeight() == 0) tmpRect.SetHeight(1); if(tmpRect.GetWidth() == 0) tmpRect.SetWidth(1); #ifdef __WXOSX__ tmpRect = rect; window->PrepareDC(dc); // Prepare the colours wxColour bgColour, penColour, textColour; textColour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); bgColour = DrawingUtils::DarkColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE), 2.0); ; // Same as the notebook background colour penColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW); penColour = bgColour; wxFont f = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); dc.SetFont(f); dc.SetPen(penColour); dc.SetBrush(bgColour); dc.DrawRectangle(tmpRect); // Fill the caption to look like OSX caption wxColour topColour("#d3d2d3"); wxColour bottomColour("#e8e8e8"); dc.GradientFillLinear(tmpRect, topColour, bottomColour, wxNORTH); dc.SetPen(penColour); dc.SetBrush(*wxTRANSPARENT_BRUSH); dc.DrawRectangle(tmpRect); int caption_offset = 0; if(pane.icon.IsOk()) { DrawIcon(dc, tmpRect, pane); caption_offset += pane.icon.GetWidth() + 3; } else { caption_offset = 3; } dc.SetTextForeground(textColour); wxCoord w, h; dc.GetTextExtent(wxT("ABCDEFHXfgkj"), &w, &h); wxRect clip_rect = tmpRect; clip_rect.width -= 3; // text offset clip_rect.width -= 2; // button padding if(pane.HasCloseButton()) clip_rect.width -= m_buttonSize; if(pane.HasPinButton()) clip_rect.width -= m_buttonSize; if(pane.HasMaximizeButton()) clip_rect.width -= m_buttonSize; wxString draw_text = wxAuiChopText(dc, text, clip_rect.width); wxSize textSize = dc.GetTextExtent(draw_text); dc.SetTextForeground(textColour); dc.DrawText(draw_text, tmpRect.x + 3 + caption_offset, tmpRect.y + ((tmpRect.height - textSize.y) / 2)); #else wxBitmap bmp(tmpRect.GetSize()); { wxMemoryDC memDc; memDc.SelectObject(bmp); wxGCDC gdc; wxDC* pDC = NULL; if(!DrawingUtils::GetGCDC(memDc, gdc)) { pDC = &memDc; } else { pDC = &gdc; } // Prepare the colours wxColour bgColour, penColour, textColour; textColour = wxSystemSettings::GetColour(wxSYS_COLOUR_WINDOWTEXT); bgColour = DrawingUtils::DarkColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE), 2.0); ; // Same as the notebook background colour penColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW); penColour = bgColour; wxFont f = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); pDC->SetFont(f); pDC->SetPen(penColour); pDC->SetBrush(bgColour); pDC->DrawRectangle(tmpRect); pDC->SetPen(penColour); pDC->SetBrush(*wxTRANSPARENT_BRUSH); pDC->DrawRectangle(tmpRect); int caption_offset = 0; if(pane.icon.IsOk()) { DrawIcon(gdc, tmpRect, pane); caption_offset += pane.icon.GetWidth() + 3; } else { caption_offset = 3; } pDC->SetTextForeground(textColour); wxCoord w, h; pDC->GetTextExtent(wxT("ABCDEFHXfgkj"), &w, &h); wxRect clip_rect = tmpRect; clip_rect.width -= 3; // text offset clip_rect.width -= 2; // button padding if(pane.HasCloseButton()) clip_rect.width -= m_buttonSize; if(pane.HasPinButton()) clip_rect.width -= m_buttonSize; if(pane.HasMaximizeButton()) clip_rect.width -= m_buttonSize; wxString draw_text = wxAuiChopText(gdc, text, clip_rect.width); wxSize textSize = pDC->GetTextExtent(draw_text); pDC->SetTextForeground(textColour); pDC->DrawText(draw_text, tmpRect.x + 3 + caption_offset, tmpRect.y + ((tmpRect.height - textSize.y) / 2)); memDc.SelectObject(wxNullBitmap); } dc.DrawBitmap(bmp, rect.x, rect.y, true); #endif }
cv::Rect SVMPlayerDetector::detectByHistogramCompare(cv::Mat videoFrame, RectScore& bestRect) { static bool debug = false; // get the accumulated histogram for player patches this->m_workFrame = videoFrame.clone(); cv::Size frameSize = videoFrame.size(); // scan the frame from left-top corner to bottom-right corner int stepWidth = 5; double bestMatchScore = 0; int bestI, bestJ; cv::namedWindow("scanPatch"); // bind the mouse event for selecting player zone //cv::setMouseCallback("scanPatch",mouseEventBB,this); cv::Mat frameClone = videoFrame.clone(); cv::imshow("scanPatch",frameClone); //cv::waitKey(0); int startY = this->m_playerZone.y; int startX = this->m_playerZone.x; int endY, endX; if(m_playerZone.height < m_bbSize.height){ m_bbSize.height = m_playerZone.height - 1; } endY = startY + this->m_playerZone.height - m_bbSize.height; if(m_playerZone.width < m_bbSize.width){ m_bbSize.width = m_playerZone.width - 1; } endX = startX + this->m_playerZone.width - m_bbSize.width; std::vector<RectScore> rectScores; for(int i = startY; i < endY; i += stepWidth) { for(int j = startX; j < endX; j += stepWidth) { // get the boundbox with (i,j) as top-left corner cv::Rect tmpRect(j,i ,m_bbSize.width, m_bbSize.height); cv::Mat tmpPatch = videoFrame(tmpRect); // calculate the histogram for tmpPatch (non-accumulate histogram) cv::MatND tmpHist = this->_getHistFromPatch(tmpPatch); // compare tmpHist to player histogram double tmpScore = this->_compareTwoHistograms(this->m_playerAccuPatch, tmpHist); cv::Mat frameClone = videoFrame.clone(); cv::rectangle(frameClone,tmpRect,CV_RGB(255,255,255),1); cv::imshow("scanPatch",frameClone); cv::waitKey(1); std::cout << tmpScore << std::endl; RectScore tmpRectScore; tmpRectScore.rect = tmpRect; tmpRectScore.score = tmpScore; rectScores.push_back(tmpRectScore); if( tmpScore > bestMatchScore) { bestMatchScore = tmpScore; bestI = i; bestJ = j; } } } std::sort(rectScores.begin(), rectScores.end(),rectScoreCompare); cv::Rect matchBB(bestJ,bestI,m_bbSize.width,m_bbSize.height); /// visualize the matched bounding box cv::namedWindow("match_bb"); const unsigned int numTop = 3; float avgX=0, avgY=0; bestRect = rectScores[0]; if(debug){ for(int i = 0; i < rectScores.size() && i < numTop; i++) { RectScore tmpRectScore = rectScores[i]; cv::Rect tmpRect = tmpRectScore.rect; avgX = avgX + tmpRect.x; avgY = avgY + tmpRect.y; std::cout << "rect score:" << tmpRectScore.score << std::endl; cv::Mat frameClone = videoFrame.clone(); cv::rectangle(frameClone,tmpRectScore.rect,cv::Scalar(255,0,0),2); cv::imshow("match_bb",frameClone); if(i == numTop -1 ){ avgX /= numTop; avgY /= numTop; // display the average bound box frameClone = videoFrame.clone(); cv::Rect avgRect = tmpRect; avgRect.x = avgX; avgRect.y = avgY; cv::rectangle(frameClone,avgRect,cv::Scalar(0,255,0),2); cv::imshow("match_bb",frameClone); } cv::waitKey(0); } } cv::destroyWindow("scanPatch"); cv::destroyWindow("match_bb"); /// return matchBB; }
DialUpView::DialUpView(BRect frame) : BView(frame, "DialUpView", B_FOLLOW_ALL, 0), fListener(this), fUpDownThread(-1), fDriverSettings(NULL), fCurrentItem(NULL), fWatching(PPP_UNDEFINED_INTERFACE_ID), fKeepLabel(false) { BRect bounds = Bounds(); // for caching SetViewUIColor(B_PANEL_BACKGROUND_COLOR); // add messenger to us so add-ons can contact us BMessenger messenger(this); fAddons.AddMessenger(DUN_MESSENGER, messenger); // create pop-up with all interfaces and "New..."/"Delete current" items fInterfaceMenu = new BPopUpMenu(kLabelCreateNew); BRect rect = bounds; rect.InsetBy(5, 5); rect.bottom = rect.top + 20; fMenuField = new BMenuField(rect, "Interfaces", kLabelInterface, fInterfaceMenu); fMenuField->SetDivider(StringWidth(fMenuField->Label()) + 5); rect.top = rect.bottom + 10; rect.bottom = bounds.bottom - 20 // height of bottom controls - 20; // space for bottom controls fTabView = new BTabView(rect, "TabView", B_WIDTH_FROM_LABEL); BRect tabViewRect(fTabView->Bounds()); tabViewRect.bottom -= fTabView->TabHeight(); fAddons.AddRect(DUN_TAB_VIEW_RECT, tabViewRect); BRect tmpRect(rect); tmpRect.top += (tmpRect.Height() - 15) / 2; tmpRect.bottom = tmpRect.top + 15; fStringView = new BStringView(tmpRect, "NoInterfacesFound", kTextNoInterfacesFound); fStringView->SetAlignment(B_ALIGN_CENTER); fStringView->Hide(); tmpRect.top = tmpRect.bottom + 10; tmpRect.bottom = tmpRect.top + 25; fCreateNewButton = new BButton(tmpRect, "CreateNewButton", kLabelCreateNewInterface, new BMessage(kMsgCreateNew)); fCreateNewButton->ResizeToPreferred(); tmpRect.left = (rect.Width() - fCreateNewButton->Bounds().Width()) / 2 + rect.left; fCreateNewButton->MoveTo(tmpRect.left, tmpRect.top); fCreateNewButton->Hide(); rect.top = rect.bottom + 15; rect.bottom = rect.top + 15; rect.right = rect.left + 200; fStatusView = new BStringView(rect, "StatusView", kTextNotConnected, B_FOLLOW_BOTTOM); rect.InsetBy(0, -5); rect.left = rect.right + 5; rect.right = bounds.right - 5; fConnectButton = new BButton(rect, "ConnectButton", kLabelConnect, new BMessage(kMsgConnectButton), B_FOLLOW_BOTTOM); AddChild(fMenuField); AddChild(fTabView); AddChild(fStringView); AddChild(fCreateNewButton); AddChild(fStatusView); AddChild(fConnectButton); // initialize LoadInterfaces(); LoadAddons(); CreateTabs(); fCurrentItem = NULL; // reset, otherwise SelectInterface will not load the settings SelectInterface(0); UpdateControls(); }
void OutputViewControlBarButton::OnPaint(wxPaintEvent& event) { int xx, yy; wxBufferedPaintDC dc(this); // Fill the background wxRect rect = GetClientSize(); dc.SetBrush( DrawingUtils::GetPanelBgColour() ); dc.SetPen ( DrawingUtils::GetPanelBgColour() ); // draw the background dc.DrawRectangle( rect ); // draw the filling wxRect tmpRect (rect); tmpRect.Deflate(2, 2); if ( m_style != 0 ) { if ( GetState() == Button_Normal ) { DrawingUtils::PaintStraightGradientBox( dc, tmpRect, wxT("WHITE"), DrawingUtils::DarkColour(wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE), DARK_FACTOR), true); } else { DrawingUtils::PaintStraightGradientBox(dc, tmpRect, wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW), wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE), true); } } // Draw the text wxFont font = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT); dc.SetTextForeground(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT)); dc.GetTextExtent(GetText(), &xx, &yy, NULL, NULL, &font); int spacer_x = m_style & Button_UseXSpacer ? BUTTON_SPACER_X : 1; bool draw_text = m_style & Button_UseText ? true : false ; // draw the bitmap int bmp_x(0); int bmp_y(0); if ( GetBmp().IsOk() ) { bmp_x = spacer_x; bmp_y = (rect.height - GetBmp().GetHeight())/2; dc.DrawBitmap(GetBmp(), bmp_x, bmp_y, true); } if ( draw_text ) { int text_x = bmp_x + GetBmp().GetWidth() + spacer_x; int text_y = (rect.height - yy) / 2; dc.SetFont( font ); dc.DrawText(GetText(), text_x, text_y); } // draw the border if ( m_style != 0 ) { dc.SetPen(wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW)); dc.SetBrush( *wxTRANSPARENT_BRUSH ); dc.DrawRoundedRectangle(rect, 1); // draw an inner white rectangle as well wxColour innerBorderCol (wxSystemSettings::GetColour(wxSYS_COLOUR_3DFACE)); innerBorderCol = DrawingUtils::LightColour(innerBorderCol, 3); dc.SetPen ( wxPen(innerBorderCol) ); dc.SetBrush( *wxTRANSPARENT_BRUSH ); rect.Deflate(1); dc.DrawRoundedRectangle(rect, 0); } }
void detect2(Mat img, vector<Mat>& regionsOfInterest,vector<Blob>& blobs){ /* Mat blurred; GaussianBlur(img, blurred, Size(), _SharpSigma, _SharpSigma); Mat lowContrastMask = abs(img - blurred) < _SharpThreshold; Mat sharpened = img*(1+_SharpAmount) + blurred*(-_SharpAmount); img.copyTo(sharpened, lowContrastMask); sharpened.copyTo(img);*/ /*************INIZIALIZZAZIONI**********/ Mat gray; Mat out = Mat::zeros(Size(WIDTH,HEIGH), CV_8U); Mat masked = Mat::zeros(Size(WIDTH,HEIGH), CV_8U); Mat morph = Mat::zeros(Size(WIDTH,HEIGH), CV_8U); Mat bwmorph = Mat::zeros(Size(WIDTH,HEIGH), CV_8U); Mat cont = Mat::zeros(Size(WIDTH,HEIGH), CV_8U); Mat maskHSV = Mat::zeros(Size(WIDTH,HEIGH), CV_8U); Mat whiteMaskMasked = Mat::zeros(Size(WIDTH,HEIGH), CV_8U); Mat whiteMaskOrig = Mat::zeros(Size(WIDTH,HEIGH), CV_8U); Mat Bands[3]; Mat noBackMask = Mat::zeros(Size(WIDTH,HEIGH), CV_8U); Mat kernelEr = getStructuringElement(MORPH_ELLIPSE,Size(5,5)); Mat thMasked; Mat thOrig; Mat bwOrig; Mat bwNoBackMask; Mat kernelOp = getStructuringElement(MORPH_ELLIPSE,Size(13,13)); vector<Mat> BGRbands; split(img,BGRbands); vector< vector<Point> > contours; /***************************************/ /*cvtColor(img,gray,CV_BGR2GRAY); gray = (gray!=0); imshow("gray",gray);*/ /*Rimozione Ombre e Background*/ // masked = applyMaskBandByBand(maskHSV,BGRbands); split(masked,BGRbands); /*Rimozione sfondo e sogliatura per videnziare esclusivamente ciò che è bianco*/ noBackMask = backgroundRemoval(img); masked = applyMaskBandByBand(noBackMask,BGRbands); /* whiteMaskOrig = computeWhiteMaskLight(img); whiteMaskOrig = whiteMaskOrig + computeWhiteMaskShadow(img); whiteMaskMasked = computeWhiteMaskLight(masked); whiteMaskMasked = whiteMaskMasked + computeWhiteMaskShadow(masked); */ CBlobResult blobsRs; blobsRs = computeWhiteMaskOtsu(img, img, blobsRs, img.rows*img.cols, img.rows*img.cols, 0.8, 0.8, 30, 200, 0); //Mat newimg(img.size(),img.type()); whiteMaskOrig.setTo(0); for(int i=0;i<blobsRs.GetNumBlobs();i++){ blobsRs.GetBlob(i)->FillBlob(whiteMaskOrig,CV_RGB(255,255,255),0,0,true); } threshold(masked,whiteMaskMasked,0,255,THRESH_BINARY); cvtColor(whiteMaskMasked,whiteMaskMasked,CV_BGR2GRAY); cout << whiteMaskMasked.type() << " " << whiteMaskOrig.type() << endl; bitwise_or(whiteMaskMasked,whiteMaskOrig,thOrig); masked = applyMaskBandByBand(thOrig,BGRbands); #if DO_MORPH /*Operazioni morfologiche per poter riempire i buchi e rimuovere i bordi frastagliati*/ dilate(masked,morph,kernelEr); erode(morph,morph,kernelEr); erode(morph,morph,kernelOp); dilate(morph,morph,kernelOp); #else morph = masked; #endif /*Ricerca componenti connesse e rimozione in base all'area*/ cvtColor(morph,bwmorph,CV_BGR2GRAY); findContours(bwmorph, contours, CV_RETR_CCOMP, CV_CHAIN_APPROX_SIMPLE); vector<double> areas = computeArea(contours); for(int j = areas.size()-1; j>=0; j--){ if(areas.at(j)>MAX_AREA || areas.at(j)<MIN_AREA ) contours.erase(contours.begin()+j); } /*Calcolo Bounding Rectangle a partire dall'immagine con componenti connesse di interesse*/ vector<Rect> boundRect( contours.size() ); vector<vector<Point> > contours_poly( contours.size() ); vector<Point2f>center( contours.size() ); vector<float>radius( contours.size() ); /*Costruzione immagine finale ed estrazione regioni di interesse*/ for (int idx = 0; idx < contours.size(); idx++){ Blob b; b.originalImage = &img; Scalar color(255); approxPolyDP( Mat(contours[idx]), contours_poly[idx], 3, true ); boundRect[idx] = boundingRect( Mat(contours_poly[idx]) ); minEnclosingCircle( (Mat)contours_poly[idx], center[idx], radius[idx] ); // Rect tmpRect(center[idx].x-boundRect[idx].width/2,center[idx].y-boundRect[idx].height/2,boundRect[idx].width,boundRect[idx].height); Rect tmpRect(center[idx].x-radius[idx],center[idx].y-radius[idx],radius[idx]*2,radius[idx]*2); //Rect tmpRect = boundRect[idx]; Rect toPrint; tmpRect += Size(tmpRect.width*RECT_AUGMENT ,tmpRect.height*RECT_AUGMENT); // Aumenta area di RECT_ARGUMENT tmpRect -= Point((tmpRect.width*RECT_AUGMENT)/2 , (tmpRect.height*RECT_AUGMENT)/2 ); // Ricentra il rettangolo drawContours(cont, contours, idx, color, CV_FILLED, 8); if(tmpRect.x>0 && tmpRect.y>0 && tmpRect.x+tmpRect.width < morph.cols && tmpRect.y+tmpRect.height < morph.rows){ //Se il nuovo rettangolo allargato // NON esce fuori dall'immagine, accettalo regionsOfInterest.push_back(masked(tmpRect)); b.cuttedWithBack = img(tmpRect); b.cuttedImages = masked(tmpRect); b.blobsImage = cont(tmpRect); b.rectangles = tmpRect; toPrint = tmpRect; } else{ toPrint = boundRect[idx]; regionsOfInterest.push_back(masked(boundRect[idx])); b.cuttedImages = masked(boundRect[idx]); b.cuttedWithBack = img(boundRect[idx]); b.rectangles = boundRect[idx]; b.blobsImage = cont(boundRect[idx]); } Point centroid = computeCentroid(contours[idx]); b.centroid = centroid; b.area = contourArea(contours[idx]); b.distance = HEIGH - centroid.y; /*rectangle( cont, toPrint.tl(), toPrint.br(), color, 2, 8, 0 ); circle( cont, center[idx], (int)radius[idx], color, 2, 8, 0 );*/ blobs.push_back(b); } //out = out+cont; bitwise_xor(out,cont,out); /*imshow("img",img); imshow("out",out); waitKey(0);*/ }
void clAuiDockArt::DrawCaption(wxDC& dc, wxWindow* window, const wxString& text, const wxRect& rect, wxAuiPaneInfo& pane) { wxRect tmpRect(wxPoint(0, 0), rect.GetSize()); // Hackishly prevent assertions on linux if (tmpRect.GetHeight() == 0) tmpRect.SetHeight(1); if (tmpRect.GetWidth() == 0) tmpRect.SetWidth(1); wxBitmap bmp(tmpRect.GetSize()); wxMemoryDC memDc; memDc.SelectObject(bmp); memDc.SetPen(*wxTRANSPARENT_PEN); memDc.SetFont(m_captionFont); // Prepare the colours bool is_dark_theme = DrawingUtils::IsThemeDark(); wxColour bgColour, penColour, textColour; if ( is_dark_theme ) { bgColour = wxColour(EditorConfigST::Get()->GetCurrentOutputviewBgColour()); penColour = DrawingUtils::DarkColour(bgColour, 5.0); textColour = *wxWHITE; } else { // Use the settings provided by a plugin // Allow the plugins to override the border colour wxColour originalPenColour = penColour; clColourEvent borderColourEvent( wxEVT_GET_TAB_BORDER_COLOUR ); if ( EventNotifier::Get()->ProcessEvent( borderColourEvent ) ) { bgColour = borderColourEvent.GetBorderColour(); penColour = DrawingUtils::DarkColour(bgColour, 3.0); if ( DrawingUtils::IsDark(bgColour) ) { textColour = *wxWHITE; } else { textColour = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT); } } else { bgColour = DrawingUtils::DarkColour(wxSystemSettings::GetColour(wxSYS_COLOUR_BTNFACE), 2.0); penColour = wxSystemSettings::GetColour(wxSYS_COLOUR_3DSHADOW); textColour = wxSystemSettings::GetColour(wxSYS_COLOUR_BTNTEXT); } } memDc.SetPen( penColour ); memDc.SetBrush( bgColour ); memDc.DrawRectangle( tmpRect ); wxPoint bottomLeft, bottomRight; bottomLeft = tmpRect.GetBottomLeft(); bottomRight = tmpRect.GetBottomRight(); bottomRight.x += 1; memDc.SetPen( bgColour ); memDc.DrawLine(bottomLeft, bottomRight); memDc.SetPen( penColour ); bottomLeft.y--; bottomRight.y--; memDc.DrawLine(bottomLeft, bottomRight); int caption_offset = 0; if ( pane.icon.IsOk() ) { DrawIcon(memDc, tmpRect, pane); caption_offset += pane.icon.GetWidth() + 3; } else { caption_offset = 3; } memDc.SetTextForeground( textColour ); wxCoord w,h; memDc.GetTextExtent(wxT("ABCDEFHXfgkj"), &w, &h); wxRect clip_rect = tmpRect; clip_rect.width -= 3; // text offset clip_rect.width -= 2; // button padding if (pane.HasCloseButton()) clip_rect.width -= m_buttonSize; if (pane.HasPinButton()) clip_rect.width -= m_buttonSize; if (pane.HasMaximizeButton()) clip_rect.width -= m_buttonSize; wxString draw_text = wxAuiChopText(memDc, text, clip_rect.width); wxSize textSize = memDc.GetTextExtent(draw_text); memDc.DrawText(draw_text, tmpRect.x+3 + caption_offset, tmpRect.y+((tmpRect.height - textSize.y)/2)); memDc.SelectObject(wxNullBitmap); dc.DrawBitmap( bmp, rect.x, rect.y, true ); }