void TextureSplatting::onPluginLoad() { // VS m_pVs = new QGLShader(QGLShader::Vertex, this); m_pVs->compileSourceFile(":/splat.vert"); // FS m_pFs = new QGLShader(QGLShader::Fragment, this); m_pFs->compileSourceFile(":/splat.frag"); // Program m_pProgram = new QGLShaderProgram(this); m_pProgram->addShader(m_pVs); m_pProgram->addShader(m_pFs); m_pProgram->link(); // Load Texture 1 glActiveTexture(GL_TEXTURE0); QString filename = QFileDialog::getOpenFileName(0, "Open Image", "/assig/grau-g/Textures", "Image file (*.png *.jpg)"); QImage img0(filename); QImage im0 = QGLWidget::convertToGLFormat(img0); glGenTextures( 1, &m_textureId0); glBindTexture(GL_TEXTURE_2D, m_textureId0); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, im0.width(), im0.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, im0.bits()); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glBindTexture(GL_TEXTURE_2D, 0); // Load Texture 2 glActiveTexture(GL_TEXTURE1); QString filename2 = QFileDialog::getOpenFileName(0, "Open Image 2", "/assig/grau-g/Textures", "Image file (*.png *.jpg)"); QImage img1(filename2); QImage im1 = QGLWidget::convertToGLFormat(img1); glGenTextures( 1, &m_textureId1); glBindTexture(GL_TEXTURE_2D, m_textureId1); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, im1.width(), im1.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, im1.bits()); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glBindTexture(GL_TEXTURE_2D, 0); // Load Texture 3 glActiveTexture(GL_TEXTURE3); QString filename3 = QFileDialog::getOpenFileName(0, "Open Image 3", "/assig/grau-g/Textures", "Image file (*.png *.jpg)"); QImage img2(filename3); QImage im2 = QGLWidget::convertToGLFormat(img2); glGenTextures( 1, &m_textureId2); glBindTexture(GL_TEXTURE_2D, m_textureId2); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, im2.width(), im2.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, im2.bits()); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glBindTexture(GL_TEXTURE_2D, 0); }
void TextureSplatting::onPluginLoad(){ // VS + FS vs=new QGLShader(QGLShader::Vertex, this); vs->compileSourceFile("/home/llop/Llop/FIB/2015-2016QT/G/Lab/NewViewer/plugins/texture-splatting/texture-splatting.vert"); fs=new QGLShader(QGLShader::Fragment, this); fs->compileSourceFile("/home/llop/Llop/FIB/2015-2016QT/G/Lab/NewViewer/plugins/texture-splatting/texture-splatting.frag"); // Program program=new QGLShaderProgram(this); program->addShader(vs); program->addShader(fs); program->link(); // Load noise glActiveTexture(GL_TEXTURE0); QString noiseFilename = QFileDialog::getOpenFileName(0, "Open Noise Image", "/assig/grau-g/Textures", "Image file (*.png *.jpg)"); QImage img3(noiseFilename); QImage im3=QGLWidget::convertToGLFormat(img3); glGenTextures( 1, &noiseId); glBindTexture(GL_TEXTURE_2D, noiseId); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, im3.width(), im3.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, im3.bits()); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glBindTexture(GL_TEXTURE_2D, 0); // Load Texture 1 glActiveTexture(GL_TEXTURE0); QString filename = QFileDialog::getOpenFileName(0, "Open Rock Image", "/assig/grau-g/Textures", "Image file (*.png *.jpg)"); QImage img0(filename); QImage im0 = QGLWidget::convertToGLFormat(img0); glGenTextures( 1, &textureId0); glBindTexture(GL_TEXTURE_2D, textureId0); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, im0.width(), im0.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, im0.bits()); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glBindTexture(GL_TEXTURE_2D, 0); // Load Texture 2 glActiveTexture(GL_TEXTURE1); QString filename2 = QFileDialog::getOpenFileName(0, "Open Grass Image", "/assig/grau-g/Textures", "Image file (*.png *.jpg)"); QImage img1(filename2); QImage im1 = QGLWidget::convertToGLFormat(img1); glGenTextures( 1, &textureId1); glBindTexture(GL_TEXTURE_2D, textureId1); glTexImage2D( GL_TEXTURE_2D, 0, GL_RGB, im1.width(), im1.height(), 0, GL_RGBA, GL_UNSIGNED_BYTE, im1.bits()); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR ); glTexParameteri( GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR ); glBindTexture(GL_TEXTURE_2D, 0); }
extern "C" void vcs_Qt_put_image_from_png_file(int id, float zoom, int vert, int horiz, char *fnm) { QImage img0(fnm); QImage img = img0.convertToFormat(QImage::Format_ARGB32_Premultiplied); QSize sz = img.size(); if (zoom != 1.) { img = img.scaledToHeight(zoom*sz.height()); } QSize sz2 = img.size(); int x1 = ((zoom -1)/2.+float(horiz)/100.)*sz.width(); int y1 = ((zoom-1)/2.+float(vert)/100.)*sz.height(); if (x1<0) x1=0; if (y1<0) y1=0; if (x1>sz2.width()-sz.width()) x1=sz2.width()-sz.width(); if (y1>sz2.height()-sz.height()) y1=sz2.height()-sz.height(); QImage *img2 = new QImage(img.copy(x1,y1,sz.width(),sz.height())); sz2 = img2->size(); vcs_Qt_window_put_qimage_by_id(id, img2); }
void run() { std::cout << "[OCV] Initializing conversion\n"; pCodecCtx = media->decode->getpCodecCtx(); pFrame = media->decode->getpFrame(); // 4.2 do somethig with OpenCV cv::Mat img0(pCodecCtx->height, pCodecCtx->width, CV_8UC3, cv::Scalar(255)); // 2.2.1. Prepare format conversion for OpenCV // Allocate an AVFrame structure pFrame_BGR24_1 = avcodec_alloc_frame(); pFrame_BGR24_2 = avcodec_alloc_frame(); if (pFrame_BGR24_1 == NULL || pFrame_BGR24_2 == NULL) { std::cout << "[OCV] Could not allocate pFrame_BGR24P\n"; exit(1); } // Determine required buffer size and allocate buffer buffer_BGR24_1 = (uint8_t *) malloc(avpicture_get_size(PIX_FMT_BGR24, pCodecCtx->width, pCodecCtx->height)); buffer_BGR24_2 = (uint8_t *) malloc(avpicture_get_size(PIX_FMT_BGR24, pCodecCtx->width, pCodecCtx->height)); // Assign buffer to image planes avpicture_fill((AVPicture *) pFrame_BGR24_1, buffer_BGR24_1, PIX_FMT_BGR24, pCodecCtx->width, pCodecCtx->height); avpicture_fill((AVPicture *) pFrame_BGR24_2, buffer_BGR24_2, PIX_FMT_BGR24, pCodecCtx->width, pCodecCtx->height); // format conversion context pConvertCtx_BGR24 = sws_getContext(pCodecCtx->width, pCodecCtx->height, pCodecCtx->pix_fmt, pCodecCtx->width, pCodecCtx->height, PIX_FMT_BGR24, SWS_SPLINE, NULL, NULL, NULL); // create new IplImage IplImage temp(img0); src = cvCloneImage(&temp); // set decoder image buffer via image qr_decoder_set_image_buffer(decoder, src); // 1.6. get video frames started = true; // text to view on image unsigned char *text = NULL; int text_size = 0; while (!terminated) { if (media->decode->frameDecoded) { // 2.2.2. convert frame to GRAYSCALE [or BGR] for OpenCV sws_scale(pConvertCtx_BGR24, (const uint8_t * const*) pFrame->data, pFrame->linesize, 0, pCodecCtx->height, pFrame_BGR24_1->data, pFrame_BGR24_1->linesize); // copy the BGR image to this object memcpy(img0.data, pFrame_BGR24_1->data[0], (pCodecCtx->width)*(pCodecCtx->height) * sizeof (uint8_t)*3); // create IplImage and copy to src IplImage temp(img0); cvCopy(&temp, src); // if save_image flag is up we need to find marker and save text buffer if (save_image) { // clear text buffer if (text) { delete text; text = NULL; } // finding markers with adaptive parameters short sz, stat; for (sz = 25, stat = 0; (sz >= 3) && ((stat & QR_IMAGEREADER_DECODED) == 0); sz -= 2) stat = qr_decoder_decode(decoder, sz); QrCodeHeader header; if (qr_decoder_get_header(decoder, &header)) { text = new unsigned char[header.byte_size + 1]; text_size = header.byte_size + 1; qr_decoder_get_body(decoder, text, text_size); save_image = false; } } // if we have text buffer if (text) { // write text to image CvFont font; cvInitFont(&font, CV_FONT_HERSHEY_COMPLEX_SMALL, 2, 2); CvPoint point; point.x = 40; point.y = 40; cvPutText(src, text, point, &font, CV_RGB(0, 255, 0)); // if need to send data to NXT if (send_data) { send_data = false; media->messageQueue->addToQueue(std::string(text)); } } // copy back the modified image memcpy(pFrame_BGR24_2->data[0], src->imageData, (pCodecCtx->width)*(pCodecCtx->height) * sizeof (uint8_t)*3); } } }