void FDMHeatWidget::initializeGL() { qDebug() << "Initialize OpenGL"; // Color de fondo gris qglClearColor(Qt::darkGray); // Activar texturas glEnable(GL_TEXTURE_2D); // Crear la textura OpenGL QImage tempImg(maxWidth, maxHeight, QImage::Format_RGB32); tempImg.fill(Qt::darkGray); texture= bindTexture(tempImg); // Inicializamos OpenCL despues de inicializar OpenGL // asi pueden compartir el contexto initializeCL(); }
/** * temporalIdalFilter - temporal IIR filtering an image pyramid of concat-frames * (Thanks to Daniel Ron & Alessandro Gentilini) * * @param pyramid - source pyramid of concatenate frames * @param filtered - concatenate filtered result * */ void VideoProcessor::temporalIdealFilter(const cv::Mat &src, cv::Mat &dst) { cv::Mat channels[3]; // split into 3 channels cv::split(src, channels); for (int i = 0; i < 3; ++i){ cv::Mat current = channels[i]; // current channel cv::Mat tempImg; int width = cv::getOptimalDFTSize(current.cols); int height = cv::getOptimalDFTSize(current.rows); cv::copyMakeBorder(current, tempImg, 0, height - current.rows, 0, width - current.cols, cv::BORDER_CONSTANT, cv::Scalar::all(0)); // do the DFT cv::dft(tempImg, tempImg, cv::DFT_ROWS | cv::DFT_SCALE); // construct the filter cv::Mat filter = tempImg.clone(); createIdealBandpassFilter(filter, fl, fh, rate); // apply filter cv::mulSpectrums(tempImg, filter, tempImg, cv::DFT_ROWS); // do the inverse DFT on filtered image cv::idft(tempImg, tempImg, cv::DFT_ROWS | cv::DFT_SCALE); // copy back to the current channel tempImg(cv::Rect(0, 0, current.cols, current.rows)).copyTo(channels[i]); } // merge channels cv::merge(channels, 3, dst); // normalize the filtered image cv::normalize(dst, dst, 0, 1, CV_MINMAX); }
Image<T> rotate(const Image<T>& srcImg, const int x, const int y, const float ang) { GVX_TRACE(__PRETTY_FUNCTION__); // make sure the source image is valid ASSERT(srcImg.initialized()); // create and clear the return image int w = srcImg.getWidth(), h = srcImg.getHeight(); Image<T> retImg(w, h, ZEROS); // create temporary working image, put srcImg in the middle // put some padding (values are 0) around the image // so we won't need to check out of bounds when rotating int pad = int(ceil(sqrt(w * w + h * h))); int wR = 2 * pad + w; int hR = 2 * pad + h; Image<T> tempImg(wR, hR, ZEROS); inplacePaste(tempImg, srcImg, Point2D<int>(pad,pad)); typename Image<T>::iterator rBPtr = retImg.beginw(); float cAng = cos(ang), sAng = sin(ang); // fill in the return image with the appropriate values float xR = 0.0; float yR = 0.0; int dx = pad + x, dy = pad + y; for(int j = -y; j < h-y; j++) for(int i = -x; i < w-x; i++) { xR = dx + i*cAng + j*sAng; yR = dy - i*sAng + j*cAng; *rBPtr++ = T(tempImg.getValInterp(xR,yR)); } return retImg; }
void CharacterSegmenter::cleanCharRegions(vector<Mat> thresholds, vector<Rect> charRegions) { const float MIN_SPECKLE_HEIGHT_PERCENT = 0.13; const float MIN_SPECKLE_WIDTH_PX = 3; const float MIN_CONTOUR_AREA_PERCENT = 0.1; const float MIN_CONTOUR_HEIGHT_PERCENT = 0.60; Mat mask = getCharBoxMask(thresholds[0], charRegions); for (int i = 0; i < thresholds.size(); i++) { bitwise_and(thresholds[i], mask, thresholds[i]); vector<vector<Point> > contours; Mat tempImg(thresholds[i].size(), thresholds[i].type()); thresholds[i].copyTo(tempImg); //Mat element = getStructuringElement( 1, // Size( 2 + 1, 2+1 ), // Point( 1, 1 ) ); //dilate(thresholds[i], tempImg, element); //morphologyEx(thresholds[i], tempImg, MORPH_CLOSE, element); //drawAndWait(&tempImg); findContours(tempImg, contours, RETR_EXTERNAL, CV_CHAIN_APPROX_SIMPLE); for (int j = 0; j < charRegions.size(); j++) { const float MIN_SPECKLE_HEIGHT = ((float)charRegions[j].height) * MIN_SPECKLE_HEIGHT_PERCENT; const float MIN_CONTOUR_AREA = ((float)charRegions[j].area()) * MIN_CONTOUR_AREA_PERCENT; int tallestContourHeight = 0; float totalArea = 0; for (int c = 0; c < contours.size(); c++) { if (contours[c].size() == 0) continue; if (charRegions[j].contains(contours[c][0]) == false) continue; Rect r = boundingRect(contours[c]); if (r.height <= MIN_SPECKLE_HEIGHT || r.width <= MIN_SPECKLE_WIDTH_PX) { // Erase this speckle drawContours(thresholds[i], contours, c, Scalar(0,0,0), CV_FILLED); if (this->config->debugCharSegmenter) { drawContours(imgDbgCleanStages[i], contours, c, COLOR_DEBUG_SPECKLES, CV_FILLED); } } else { if (r.height > tallestContourHeight) tallestContourHeight = r.height; totalArea += contourArea(contours[c]); } //else if (r.height > tallestContourHeight) //{ // tallestContourIndex = c; // tallestContourHeight = h; //} } if (totalArea < MIN_CONTOUR_AREA) { // Character is not voluminous enough. Erase it. if (this->config->debugCharSegmenter) { cout << "Character CLEAN: (area) removing box " << j << " in threshold " << i << " -- Area " << totalArea << " < " << MIN_CONTOUR_AREA << endl; Rect boxTop(charRegions[j].x, charRegions[j].y - 10, charRegions[j].width, 10); rectangle(imgDbgCleanStages[i], boxTop, COLOR_DEBUG_MIN_AREA, -1); } rectangle(thresholds[i], charRegions[j], Scalar(0, 0, 0), -1); } else if (tallestContourHeight < ((float) charRegions[j].height * MIN_CONTOUR_HEIGHT_PERCENT)) { // This character is too short. Black the whole thing out if (this->config->debugCharSegmenter) { cout << "Character CLEAN: (height) removing box " << j << " in threshold " << i << " -- Height " << tallestContourHeight << " < " << ((float) charRegions[j].height * MIN_CONTOUR_HEIGHT_PERCENT) << endl; Rect boxBottom(charRegions[j].x, charRegions[j].y + charRegions[j].height, charRegions[j].width, 10); rectangle(imgDbgCleanStages[i], boxBottom, COLOR_DEBUG_MIN_HEIGHT, -1); } rectangle(thresholds[i], charRegions[j], Scalar(0, 0, 0), -1); } } Mat closureElement = getStructuringElement( 1, Size( 2 + 1, 2+1 ), Point( 1, 1 ) ); //morphologyEx(thresholds[i], thresholds[i], MORPH_OPEN, element); //dilate(thresholds[i], thresholds[i], element); //erode(thresholds[i], thresholds[i], element); morphologyEx(thresholds[i], thresholds[i], MORPH_CLOSE, closureElement); // Lastly, draw a clipping line between each character boxes for (int j = 0; j < charRegions.size(); j++) { line(thresholds[i], Point(charRegions[j].x - 1, charRegions[j].y), Point(charRegions[j].x - 1, charRegions[j].y + charRegions[j].height), Scalar(0, 0, 0)); line(thresholds[i], Point(charRegions[j].x + charRegions[j].width + 1, charRegions[j].y), Point(charRegions[j].x + charRegions[j].width + 1, charRegions[j].y + charRegions[j].height), Scalar(0, 0, 0)); } } }