VideoTeror::GrayscaleImage VideoTeror::MotionDetection::FarnebackMotionDetector::detect(const GrayscaleImage &curFrame) { GrayscaleImage resized; cv::resize(curFrame, resized, cv::Size(prevFrame.cols, prevFrame.rows)); cv::Mat_<cv::Vec2f> flow(resized.rows, resized.cols); cv::calcOpticalFlowFarneback(prevFrame, resized, flow, 0.75, 3, 10, 20, 5, 1.1, 0); GrayscaleImage test; curFrame.copyTo(test); GrayscaleImage result(resized.rows, resized.cols); for (int y = 0; y < resized.rows; y++) { for (int x = 0; x < resized.cols; x++) { cv::line(test, cv::Point(x*blockSize, y*blockSize), cv::Point(x*blockSize + flow(y, x)[0]*blockSize, y*blockSize + flow(y, x)[1]*blockSize), 255); result(y, x) = 255 * (sqrt(flow(y, x)[0]*flow(y, x)[0] + flow(y, x)[1]*flow(y, x)[1])); // > threshold); } } morphClosure(result, 4); cv::imshow("test", test); resized.copyTo(prevFrame); cv::resize(result, result, cv::Size(curFrame.cols, curFrame.rows), 0, 0, cv::INTER_NEAREST); return result; }
/*--------------------------------------------------------------------------- Cration d'une pyramide Laplacienne avec entre en conversationnel des diffrentes proprits de cette pyramide ---------------------------------------------------------------------------*/ Image *Pyramid::pyram_l (const Image *im, int etage_f, filtre &utile, string &to_print) { if(!( im != NULL )) { throw "Error in Pyramid::pyram_g:\nim = NULL"; } if(!( im->getWidth() == im->getHeight() )) { throw "Error in Pyramid::pyram_g:\nim->getWidth() != im->getHeight()"; } if( !isPowerOf2(im->getWidth()) ) { throw "Error in Pyramid::pyram_g:\nimage dimensions not a power of 2"; } long nbl = im->getHeight(); long nbc = im->getWidth(); const uint8_t* itab = im->begin(); // uint8_t* rep = new uint8_t[nbc * nbl * 2]; GrayscaleImage* resImg = new GrayscaleImage(im->getWidth(), im->getHeight() * 2); uint8_t* rep = resImg->begin(); int temp_etage_max = etage_max( im ); if( etage_f > temp_etage_max ) etage_f = temp_etage_max; if( etage_f < 1 ) etage_f = 1; pyram_l_n(rep,etage_f,nbc,nbl,itab,utile); to_print = entropie_p(rep,etage_f,nbc,nbl); reconstruction(rep,etage_f,nbc,nbl); return resImg; }
void SplitColorOp:: operator()(const imagein::Image* image, const std::map<const imagein::Image*, std::string>&) { for(unsigned int c = 0; c < image->getNbChannels(); ++c) { GrayscaleImage* resImg = new GrayscaleImage(image->getWidth(), image->getHeight()); for(unsigned int j = 0; j < resImg->getHeight(); ++j) { for(unsigned int i = 0; i < resImg->getWidth(); ++i) { resImg->setPixel(i, j, image->getPixel(i, j, c)); } } QString name(""); name += Tools::colorName(c, image->getNbChannels()); this->outImage(resImg, name.toStdString()); } }
/*--------------------------------------------------------------------------- Cration d'un tage de la pyramide Laplacienne ---------------------------------------------------------------------------*/ Image *Pyramid::n_pyram_l(const Image *im, int etage_f, filtre &utile) { if(!( im != NULL )) { throw "Error in Pyramid::pyram_g:\nim = NULL"; } if(!( im->getWidth() == im->getHeight() )) { throw "Error in Pyramid::pyram_g:\nim->getWidth() != im->getHeight()"; } if( !isPowerOf2(im->getWidth()) ) { throw "Error in Pyramid::pyram_g:\nimage dimensions not a power of 2"; } int i; int k=0; int taille_c,taille_l; long nbl = im->getHeight(); long nbc = im->getWidth(); const uint8_t* itab = im->begin(); taille_c=nbc; taille_l=nbl; int temp_etage_max = etage_max(im) - 1; if( etage_f > temp_etage_max ) etage_f = temp_etage_max; if( etage_f < 0 ) etage_f = 0; for(i=0;i<etage_f;i++) { k=k+taille_c*taille_l; taille_c=taille_c/2; taille_l=taille_l/2; } GrayscaleImage* resImg = new GrayscaleImage(taille_c, taille_l); uint8_t* rep = resImg->begin(); uint8_t* tab = new uint8_t[(nbc * nbc) / 2 * 3]; pyram_g_n(tab,etage_f,nbc,nbl,itab,utile); pyram_l_n(tab,etage_f+1,nbc,nbl,itab,utile); for(i=0;i<taille_c*taille_l;i++) { rep[i] = tab[i+k]; } delete[] tab; return resImg; }
VideoTeror::GrayscaleImage VideoTeror::MotionDetection::BackgroundSubtractorDetector::detect(const GrayscaleImage &curFrame) { GrayscaleImage frame; cv::resize(curFrame, frame, cv::Size(curFrame.cols/scaleParam, curFrame.rows/scaleParam)); bs(frame, foreground); GrayscaleImage result = GrayscaleImage::zeros(frame.rows, frame.cols); for (int r = 0; r < frame.rows; r++) { for (int c = 0; c < frame.cols; c++) { if (foreground(r,c) > 0) result(r,c) = 255; } } morphClosure(result, morphClosureParam); cv::resize(result, result, cv::Size(curFrame.cols, curFrame.rows)); //cv::Mat bg; //bs.getBackgroundImage(bg); //cv::imshow("foreground", foreground); return result.clone(); }
void PseudoColorOp::operator()(const imagein::Image* image, const std::map<const imagein::Image*, std::string>&) { GrayscaleImage* tmpImg = Converter<GrayscaleImage>::convert(*image); Image* resImg = new Image(tmpImg->getWidth(), tmpImg->getHeight(), 3); for(unsigned int j = 0; j < tmpImg->getHeight(); ++j) { for(unsigned int i = 0; i < tmpImg->getWidth(); ++i) { Image::depth_t value = tmpImg->getPixel(i, j); const int nhue = 256; const int ngrad = ceil(256. / (double)nhue); const int hue = floor(value * nhue / 256); /* € [0, nhue[ */ const int grad = value - ceil((double)hue * 256. / (double)nhue); /* € [0, ngrad[ */ QColor color = QColor::fromHsl(300 - hue * 300 / nhue, 255, (grad + 1) * 255 / (ngrad + 1)); resImg->setPixel(i, j, 0, color.red()); resImg->setPixel(i, j, 1, color.green()); resImg->setPixel(i, j, 2, color.blue()); } } delete tmpImg; outImage(resImg, qApp->translate("PseudoColorOp", "Pseudo color").toStdString()); }