void Sakbot::findSegmentation() { // init createGreyscale(); // colored background m_bgSubtractorColor(m_image,m_segmentation); m_bgSubtractorColor.getBackgroundImage(m_background); // initial segmentation m_bgSubtractor(m_imageGrey,m_segmentation); m_bgSubtractor.getBackgroundImage(m_backgroundGrey); // close holes cv::dilate(m_segmentation,m_segmentation,cv::Mat(),cv::Point(-1,-1),2); cv::erode(m_segmentation,m_segmentation,cv::Mat(),cv::Point(-1,-1),2); showPics(m_segmentation, "mask1", 20, 20); // create frames needed for shadow detection cv::cvtColor(m_image,m_imageHSV,CV_BGR2HSV); cv::cvtColor(m_background,m_backgroundHSV,CV_BGR2HSV); // get rid of the shadows findShadows(); // combine cv::Mat temp; cv::bitwise_not(m_shadowSegmentation, temp); cv::bitwise_and(m_segmentation, temp, m_segmentation); showPics(m_segmentation, "mask-shadow", 20, 400); // close holes cv::dilate(m_segmentation,m_segmentation,cv::Mat(),cv::Point(-1,-1),2); cv::erode(m_segmentation,m_segmentation,cv::Mat(),cv::Point(-1,-1),2); // get rid of small fragments cv::erode(m_segmentation,m_segmentation,cv::Mat(),cv::Point(-1,-1),m_segmentationErode); cv::dilate(m_segmentation,m_segmentation,cv::Mat(),cv::Point(-1,-1),m_segmentationDilate); // do a final second segmentation based on the mask and difference to the background finalizeSegmentation(); // last "smoothing" cv::dilate(m_segmentation,m_segmentation,cv::Mat(),cv::Point(-1,-1),2); cv::erode(m_segmentation,m_segmentation,cv::Mat(),cv::Point(-1,-1),2); }
void showMotd(W_Window win) { int i; struct list *data; int count; int headernum; newMotdStuff = 0; /* clear the flag */ if (currpage == NULL) currpage = motddata; if (currpage == NULL) return; if (!W_IsMapped(win)) return; headernum = currpage->page % NRHEADERS; W_ClearWindow(win); if(xpm) W_DrawImageNoClip(win, 0, 0, 0, getImage(I_HEADER), 0); else { W_Image *headerA, *headerB, *header1; headerA = getImage(I_HEADERA); headerB = getImage(I_HEADERB); header1 = getImage(I_HEADER1); W_DrawImageNoClip(win, 0, 0, 0, headerA, foreColor); W_DrawImageNoClip(win, headerA->width, 0, 0, headerB, foreColor); W_DrawImageNoClip(win, headerA->width, headerB->height, 0, getImage(I_HEADER1 + headernum), foreColor); if (headernum == 2) { /* fill in client: */ /* note: font dependant */ } else if (headernum == 3) {/* fill in server: */ ; } } if (currpage->first) { currpage->first = 0; data = currpage->text; while (data != NULL) { data->bold = checkBold(data->data); data = data->next; } } data = currpage->text; count = LINESPERPAGE; /* Magical # of lines to display */ i = getImage(I_HEADERA)->height / (paradise ? 10 : W_Textheight) + 1; while (count > 0) { if (data == NULL) break; if (data->bold) { W_WriteText(win, 20, i * (paradise ? 10 : W_Textheight), textColor, data->data, strlen(data->data), W_BoldFont); } else { W_WriteText(win, 20, i * (paradise ? 10 : W_Textheight), textColor, data->data, strlen(data->data), W_RegularFont); } data = data->next; count--; i++; } if (win == w) { count = (int)W_StringWidth(blk_refitstring, W_RegularFont) / 2; W_WriteText(mapw, 250 - count, 480, textColor, blk_refitstring, strlen(blk_refitstring), W_RegularFont); } showPics(win); /* showValues(mapw); Should be handled in event loop now RF */ /* keep the warning visible [BDyess] */ if(hudwarning && warncount) { W_MaskText(w, center - (warncount / 2) * W_Textwidth, HUD_Y, W_Green, warningbuf, warncount, W_RegularFont); } /* flush buffer if one exists [BDyess] */ if(W_IsBuffered(win)) W_DisplayBuffer(win); }
// SEGMENTATION ##################################################### void Sakbot::findShadows() { // formula: // B = background image (HSV) // I = main image (HSV) // a = control parameter for lightsource strength (brighter the source => smaller a) // b = control parameter for noise sensitivity // if the pixel is part of the segmentation continue // if a < V(I)/V(B) < b continue // if |S(I)-S(B)| <= satThresh continue // if |H(I)-H(B)| <= hueThresh shadowpoint found int rows = m_imageHSV.rows; int cols = m_imageHSV.cols; m_shadowSegmentation = cv::Mat(m_imageHSV.clone()); for(int i=0; i<rows; i++) for(int j=0; j<cols; j++) { // apply formula for each pixel if( m_segmentation.at<uchar>(i,j) == 0 ) { m_shadowSegmentation.at<cv::Vec3b>(i,j)[0] = 0; m_shadowSegmentation.at<cv::Vec3b>(i,j)[1] = 0; m_shadowSegmentation.at<cv::Vec3b>(i,j)[2] = 0; continue; } double v; int iV = m_imageHSV.at<cv::Vec3b>(i,j)[2]; int bV = m_backgroundHSV.at<cv::Vec3b>(i,j)[2]; iV = (iV == 0)? 1 : iV; bV = (bV == 0)? 1 : bV; v = iV/(double)bV; if( m_aParam > v || m_bParam < v) { m_shadowSegmentation.at<cv::Vec3b>(i,j)[0] = 0; m_shadowSegmentation.at<cv::Vec3b>(i,j)[1] = 0; m_shadowSegmentation.at<cv::Vec3b>(i,j)[2] = 0; continue; } int s = m_imageHSV.at<cv::Vec3b>(i,j)[1]-m_backgroundHSV.at<cv::Vec3b>(i,j)[1]; s = (s < 0)? -s : s; if( s > m_satThresh ) { m_shadowSegmentation.at<cv::Vec3b>(i,j)[0] = 0; m_shadowSegmentation.at<cv::Vec3b>(i,j)[1] = 0; m_shadowSegmentation.at<cv::Vec3b>(i,j)[2] = 0; continue; } int h = m_imageHSV.at<cv::Vec3b>(i,j)[0]-m_backgroundHSV.at<cv::Vec3b>(i,j)[0]; h = (h < 0)? -h : h; if( h > m_hueThresh ) { m_shadowSegmentation.at<cv::Vec3b>(i,j)[0] = 0; m_shadowSegmentation.at<cv::Vec3b>(i,j)[1] = 0; m_shadowSegmentation.at<cv::Vec3b>(i,j)[2] = 0; continue; } // test passed -> mask pixel m_shadowSegmentation.at<cv::Vec3b>(i,j)[0] = 255; m_shadowSegmentation.at<cv::Vec3b>(i,j)[1] = 255; m_shadowSegmentation.at<cv::Vec3b>(i,j)[2] = 255; } showPics(m_shadowSegmentation, "shadow1", 420, 20); cv::cvtColor(m_shadowSegmentation, m_shadowSegmentation, CV_RGB2GRAY); cv::dilate(m_shadowSegmentation,m_shadowSegmentation,cv::Mat(),cv::Point(-1,-1),m_shadowDilate); cv::erode(m_shadowSegmentation,m_shadowSegmentation,cv::Mat(),cv::Point(-1,-1),m_shadowErode); showPics(m_shadowSegmentation, "shadowPost", 420, 400); m_shadowSegmentationFull = m_shadowSegmentation.clone(); }