void Ut_MGLE2Renderer::testDrawing() { #ifdef M_USE_OPENGL QGLWidget glw; glw.resize(67,67); glw.makeCurrent(); MGLES2Renderer::activate(&glw); MGLES2Renderer* r = MGLES2Renderer::instance(); QPixmap pm(32,32); pm.fill(Qt::red); //draw with default shader r->setViewportSize(glw.size()); r->begin(NULL); r->bindTexture(pm); r->draw(QRect(1,1,32,32)); r->draw(34,1); r->draw(1,34,32,32); r->setInvertTexture(true); r->draw(QRect(34,34,32,32), QRect(4,4,24,24)); r->end(); //draw with custom shader r->begin(NULL, r->getShaderProgram(qApp->applicationDirPath() + "/shader1.frag", qApp->applicationDirPath() + "/shader1.vert")); r->bindTexture(pm); r->draw(17,17,33,33); r->end(); //compare resulted image with reference image QImage image1 = glw.grabFrameBuffer(); //image1.save("glw1.png", "PNG"); QImage image2(qApp->applicationDirPath() + "/glw1.png", "PNG"); QVERIFY(image1 == image2); //draw patches glw.resize(64,64); QList<QRect> targets; targets.append(QRect(0,0,32,32)); targets.append(QRect(32,0,32,32)); targets.append(QRect(0,32,32,32)); targets.append(QRect(32,32,32,32)); QList<QRect> sources; sources.append(QRect(17,17,16,16)); sources.append(QRect(32,17,16,16)); sources.append(QRect(17,32,16,16)); sources.append(QRect(32,32,16,16)); pm.convertFromImage(image2); r->begin(NULL); r->bindTexture(pm); r->draw(targets, sources); r->end(); //compare resulted image with reference image image1 = glw.grabFrameBuffer(); //image1.save("glw2.png", "PNG"); image2.load(qApp->applicationDirPath() + "/glw2.png", "PNG"); QVERIFY(image1 == image2); #endif }
void TestGPURayCaster::testSetImages() { vtkImageDataPtr data = vtkImageData::New(); cx::ImagePtr image1(new cx::Image("i1", data)); cx::ImagePtr image2(new cx::Image("i2", data)); cx::ImagePtr image3(new cx::Image("i3", data)); cx::ImagePtr image4(new cx::Image("i4", data)); cx::ImagePtr image5(new cx::Image("i5", data)); std::vector<cx::ImagePtr> images; uint64_t mTime = mRep->mActor->GetMTime(); images.push_back(image1); CPPUNIT_ASSERT_EQUAL((size_t)0, mRep->getImages().size()); mRep->setImages(images); CPPUNIT_ASSERT_EQUAL((size_t)1, mRep->getImages().size()); CPPUNIT_ASSERT_EQUAL(QString("i1"), mRep->getImages()[0]->getUid()); CPPUNIT_ASSERT(mRep->mActor->GetMTime() > mTime); mTime = mRep->mActor->GetMTime(); mRep->setImages(images); uint64_t mNewTime = mRep->mActor->GetMTime(); CPPUNIT_ASSERT_EQUAL(mTime, mNewTime); images.push_back(image2); images.push_back(image3); images.push_back(image4); images.push_back(image5); mRep->setImages(images); CPPUNIT_ASSERT_EQUAL((size_t)4, mRep->getImages().size()); CPPUNIT_ASSERT_EQUAL(QString("i1"), mRep->getImages()[0]->getUid()); CPPUNIT_ASSERT_EQUAL(QString("i2"), mRep->getImages()[1]->getUid()); CPPUNIT_ASSERT_EQUAL(QString("i3"), mRep->getImages()[2]->getUid()); CPPUNIT_ASSERT_EQUAL(QString("i4"), mRep->getImages()[3]->getUid()); }
int main(int argc, char **argv){ if(argc<2){ std::cout<<"Need to specify the calibration file"<<std::endl; return 1; } Mat img1,img2; TwinCamera twin(0,1); twin.getDoubleImages(img1,img2); twin.loadCameraParameters(argv[1], img1, img2); Screen image1("Image1"); Screen image2("Image2"); Screen disp("Disparity"); StereoDepth stereoDepth; char c = 0; while(c!=27){ switch(c){ case '1': image1.putImage(img1); image2.putImage(img2); break; case '3': twin.getDoubleImages(img1,img2); twin.rectifyForStereo(img1, img2); stereoDepth.setImage1(img1); stereoDepth.setImage2(img2); if(stereoDepth.doDepth()){ disp.putImage(stereoDepth.getDisparity()); }break; } c = waitKey(10); } }
void compute_cone_chase_statistics(spot_tracker_XY &tracker, double radius, double posaccuracy, int count, double &minerr, double &maxerr, double &sumerr, double &biasx, double &biasy, double &x, double &y) { int i; tracker.set_radius(radius); tracker.set_pixel_accuracy(posaccuracy); tracker.set_location(x,y); minerr = 1000; maxerr = 0; sumerr = 0; biasx = 0; biasy = 0; for (i = 0; i < count; i++) { double testx = x + ( (rand()/(double)(RAND_MAX)) - 0.5) * (radius/2); double testy = y + ( (rand()/(double)(RAND_MAX)) - 0.5) * (radius/2); { cone_image image2(0,255, 0,255, 127, 5, testx, testy, radius, 250); tracker.optimize_xy(image2, 0, x, y); double err = sqrt( (x-testx)*(x-testx) + (y-testy)*(y-testy) ); if (err < minerr) { minerr = err; } if (err > maxerr) { maxerr = err; } sumerr += err; biasx += x - testx; biasy += y - testy; } } }
void ResultsJsInterface::pushImageToClipboard(const QByteArray &base64, const QString &html) { QMimeData *mimeData = new QMimeData(); QByteArray byteArray = QByteArray::fromBase64(base64); QImage pm; if(pm.loadFromData(byteArray)) { #ifdef __WIN32__ //needed because jpegs/clipboard doesn't support transparency in windows QImage image2(pm.size(), QImage::Format_ARGB32); image2.fill(Qt::white); QPainter painter(&image2); painter.drawImage(0, 0, pm); mimeData->setImageData(image2); #else mimeData->setImageData(pm); #endif } if ( ! html.isEmpty()) mimeData->setHtml(html); if (mimeData->hasImage() || mimeData->hasHtml()) { QClipboard *clipboard = QApplication::clipboard(); clipboard->setMimeData(mimeData, QClipboard::Clipboard); } }
int main( int argc, char * argv[] ) { const char * WINDOW_NAME = "Appended Images"; if( argc <= NUM_OF_ARGS ) { std::cerr << "Need " << NUM_OF_ARGS << " args. sift <image1> <image1_key> <image2> <image2_key>"; exit( -1 ); } ImageRAII image1( argv[1] ); ImageRAII image2( argv[3] ); std::pair< CvMat *, CvMat * > tmp1; std::pair< CvMat *, CvMat * > tmp2; std::pair< MatrixRAII, MatrixRAII > image1_keys; std::pair< MatrixRAII, MatrixRAII > image2_keys; tmp1 = readkeys( argv[2] ); image1_keys.first.matrix = tmp1.first; image1_keys.second.matrix = tmp1.second; tmp2 = readkeys( argv[4] ); image2_keys.first.matrix = tmp2.first; image2_keys.second.matrix = tmp2.second; ImageRAII appended_images = match( image1.image, image2.image, tmp1, tmp2 ); cvNamedWindow( WINDOW_NAME ); cvShowImage( WINDOW_NAME, appended_images.image ); cvWaitKey( 0 ); return 0; }
// Test that a draw that only partially covers the drawing surface isn't // interpreted as covering the entire drawing surface (i.e., exercise one of the // conditions of SkCanvas::wouldOverwriteEntireSurface()). DEF_TEST(Image_RetainSnapshot, reporter) { const SkPMColor red = SkPackARGB32(0xFF, 0xFF, 0, 0); const SkPMColor green = SkPackARGB32(0xFF, 0, 0xFF, 0); SkImageInfo info = SkImageInfo::MakeN32Premul(2, 2); SkAutoTUnref<SkSurface> surface(SkSurface::NewRaster(info)); surface->getCanvas()->clear(0xFF00FF00); SkPMColor pixels[4]; memset(pixels, 0xFF, sizeof(pixels)); // init with values we don't expect const SkImageInfo dstInfo = SkImageInfo::MakeN32Premul(2, 2); const size_t dstRowBytes = 2 * sizeof(SkPMColor); SkAutoTUnref<SkImage> image1(surface->newImageSnapshot()); REPORTER_ASSERT(reporter, image1->readPixels(dstInfo, pixels, dstRowBytes, 0, 0)); for (size_t i = 0; i < SK_ARRAY_COUNT(pixels); ++i) { REPORTER_ASSERT(reporter, pixels[i] == green); } SkPaint paint; paint.setXfermodeMode(SkXfermode::kSrc_Mode); paint.setColor(SK_ColorRED); surface->getCanvas()->drawRect(SkRect::MakeXYWH(1, 1, 1, 1), paint); SkAutoTUnref<SkImage> image2(surface->newImageSnapshot()); REPORTER_ASSERT(reporter, image2->readPixels(dstInfo, pixels, dstRowBytes, 0, 0)); REPORTER_ASSERT(reporter, pixels[0] == green); REPORTER_ASSERT(reporter, pixels[1] == green); REPORTER_ASSERT(reporter, pixels[2] == green); REPORTER_ASSERT(reporter, pixels[3] == red); }
int main(int argc,char *argv[]) { QApplication app(argc,argv); { QTextCodec::setCodecForLocale(QTextCodec::codecForName(LOCAL_CODEC_)); QDir::addSearchPath("images",app.applicationDirPath()+"/Images"); QDir::addSearchPath("images",BUILD_PATH_); QDir::addSearchPath("images",BUILD_PATH_"/../Images"); } Window window; { QImage image1("images:000002"),image2("images:000003"); window.addImage( image1 )->setTitle("src1"); window.addImage( image2 )->setTitle("src2"); cv::Mat mat1 = qImage2OpencvMat( image1 ); cv::Mat mat2 = qImage2OpencvMat( image2 ); cv::Mat ans; cv::addWeighted(mat1,0.3,mat2,0.7,0.0 ,ans); window.addImage( opencvMat2QImage(ans) )->setTitle("add_0"); window.addImage( opencvMat2QImage( 0.7*mat1 + 0.3*mat2+cv::Scalar(0.1,0.2,0.3) ) )->setTitle("add_1"); } window.show(); return app.exec(); }
int main(int argc, char const *argv[]) { int n = argc < 2 ? 2 : atoi(argv[1]); omp_set_num_threads(n); omp_set_dynamic(0); printf("set number of threads to %d\n",n); printf("disabled dynamic\n"); double pmin = -2.25, pmax = 0.75, qmin = -1.5, qmax = 1.5; double maxv = 100; int maxk = 256; int w = 640; int h = 480; double tp = omp_get_wtime(); std::vector<unsigned char> image(w*h); std::vector<unsigned char> image2(w*h); #pragma omp parallel { #pragma omp single { printf("warmup\n"); } } printf("all grid testing using runtime (OMP_SCHEDULE) environment variable\n"); double t0 = omp_get_wtime(); #pragma omp parallel for shared(image) firstprivate(h,w) collapse(2) schedule(runtime) for(int i = 0; i < h; i++) for(int j = 0; j < w; j++) { int k = mandel(i*((pmax-pmin)/h)+pmin,j*((qmax-qmin)/w)+qmin, maxv, maxk); image[i*w+j] = k >= maxk ? 0 : k; image2[i*w+j] = omp_get_thread_num()*256/n; } stbi_write_png("outgrid_result.png",w,h,1,&image[0],w); stbi_write_png("outgrid_assign.png",w,h,1,&image2[0],w); double t1 = omp_get_wtime(); printf("Output is %f and warmup %f\n",t1-t0,t0-tp); printf("only row testing using runtime (OMP_SCHEDULE) environment variable\n"); { double t0 = omp_get_wtime(); W ww(10); // NOTE: cannot use nor private or firstprivate for ww #pragma omp parallel for shared(image) firstprivate(h,w) schedule(runtime) shared(ww) for(int i = 0; i < h; i++) for(int j = 0; j < w; j++) { int k = mandel(i*((pmax-pmin)/h)+pmin,j*((qmax-qmin)/w)+qmin, maxv, maxk); image[i*w+j] = k >= maxk ? 0 : k; image2[i*w+j] = omp_get_thread_num()*256/n; } stbi_write_png("outrows_result.png",w,h,1,&image[0],w); stbi_write_png("outrows_assign.png",w,h,1,&image2[0],w); double t1 = omp_get_wtime(); printf("Output is %f and warmup %f\n",t1-t0,t0-tp); } return 0; }
void takePictureBase(){ //printf("picture base\n"); cv::Mat image2(720, 1280, CV_8UC3); cap.read(image2); image2.copyTo(baseFrame); //cap.read(image2); //image2.copyTo(baseFrame); }
bool Texture::Load() { int Index = m_FileName.find("."); if(m_FileName.substr(Index) == ".png") { std::vector<uByte> Image; unsigned error = lodepng::decode(Image, m_Width, m_Height, m_FileName); if(error != 0) { BC_LOG("Error %u : %s\n", error, lodepng_error_text(error)); return false; } size_t u2 = 1; while(u2 < m_Width) u2 *= 2; size_t v2 = 1; while(v2 < m_Height) v2 *= 2; double u3 = (double)m_Width / u2; double v3 = (double)m_Height / v2; std::vector<unsigned char> image2(u2 * v2 * 4); for(size_t y = 0; y < m_Height; y++) for(size_t x = 0; x < m_Width; x++) for(size_t c = 0; c < 4; c++) { image2[4 * u2 * y + 4 * x + c] = Image[4 * m_Width * y + 4 * x + c]; } GLfloat fLargest; glGetFloatv(GL_TEXTURE_MAX_ANISOTROPY_EXT, &fLargest); glGenTextures(1, &m_Texture); glBindTexture(GL_TEXTURE_2D, m_Texture); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAX_ANISOTROPY_EXT, fLargest); glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, u2, v2, 0, GL_RGBA, GL_UNSIGNED_BYTE, &image2[0]); m_Width = u2; m_Height = v2; } else { m_Texture = SOIL_load_OGL_texture ( m_FileName.c_str(), SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT ); if( 0 == m_Texture ) { BC_LOG("image loading error: '%s'\n", SOIL_last_result()); } glBindTexture(GL_TEXTURE_2D, m_Texture); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); } return true; }
int Product::qt_metacall(QMetaObject::Call _c, int _id, void **_a) { _id = QObject::qt_metacall(_c, _id, _a); if (_id < 0) return _id; #ifndef QT_NO_PROPERTIES if (_c == QMetaObject::ReadProperty) { void *_v = _a[0]; switch (_id) { case 0: *reinterpret_cast< QString*>(_v) = id(); break; case 1: *reinterpret_cast< QString*>(_v) = description(); break; case 2: *reinterpret_cast< QString*>(_v) = longdescription(); break; case 3: *reinterpret_cast< QString*>(_v) = longtext(); break; case 4: *reinterpret_cast< QString*>(_v) = image1(); break; case 5: *reinterpret_cast< QString*>(_v) = image2(); break; case 6: *reinterpret_cast< QString*>(_v) = image3(); break; case 7: *reinterpret_cast< QString*>(_v) = catid(); break; case 8: *reinterpret_cast< QString*>(_v) = subcatid(); break; } _id -= 9; } else if (_c == QMetaObject::WriteProperty) { void *_v = _a[0]; switch (_id) { case 0: setId(*reinterpret_cast< QString*>(_v)); break; case 1: setDescription(*reinterpret_cast< QString*>(_v)); break; case 2: setLongDescription(*reinterpret_cast< QString*>(_v)); break; case 3: setLongText(*reinterpret_cast< QString*>(_v)); break; case 4: setImage1(*reinterpret_cast< QString*>(_v)); break; case 5: setImage2(*reinterpret_cast< QString*>(_v)); break; case 6: setImage2(*reinterpret_cast< QString*>(_v)); break; case 7: setCatId(*reinterpret_cast< QString*>(_v)); break; case 8: setSubCatId(*reinterpret_cast< QString*>(_v)); break; } _id -= 9; } else if (_c == QMetaObject::ResetProperty) { _id -= 9; } else if (_c == QMetaObject::QueryPropertyDesignable) { _id -= 9; } else if (_c == QMetaObject::QueryPropertyScriptable) { _id -= 9; } else if (_c == QMetaObject::QueryPropertyStored) { _id -= 9; } else if (_c == QMetaObject::QueryPropertyEditable) { _id -= 9; } else if (_c == QMetaObject::QueryPropertyUser) { _id -= 9; } else if (_c == QMetaObject::RegisterPropertyMetaType) { if (_id < 9) *reinterpret_cast<int*>(_a[0]) = -1; _id -= 9; } #endif // QT_NO_PROPERTIES return _id; }
void run(cv::Mat& image,cv::Mat& outImage,cv::Mat& outMinTrace,cv::Mat& outDeletedLine) { cv::Mat image_gray(image.rows,image.cols,CV_8U,cv::Scalar(0)); cv::cvtColor(image,image_gray,CV_BGR2GRAY); //彩色图像转换为灰度图像 cv::Mat gradiant_H(image.rows,image.cols,CV_32F,cv::Scalar(0));//水平梯度矩阵 cv::Mat gradiant_V(image.rows,image.cols,CV_32F,cv::Scalar(0));//垂直梯度矩阵 cv::Mat kernel_H = (cv::Mat_<float>(3,3) << 0, 0, 0, 0, 1, -1, 0, 0, 0); //求水平梯度所使用的卷积核(赋初始值) cv::Mat kernel_V = (cv::Mat_<float>(3,3) << 0, 0, 0, 0, 1, 0, 0, -1, 0); //求垂直梯度所使用的卷积核(赋初始值) cv::filter2D(image_gray,gradiant_H,gradiant_H.depth(),kernel_H); cv::filter2D(image_gray,gradiant_V,gradiant_V.depth(),kernel_V); cv::Mat gradMag_mat(image.rows,image.rows,CV_32F,cv::Scalar(0)); cv::add(cv::abs(gradiant_H),cv::abs(gradiant_V),gradMag_mat);//水平与垂直滤波结果的绝对值相加,可以得到近似梯度大小 ////如果要显示梯度大小这个图,因为gradMag_mat深度是CV_32F,所以需要先转换为CV_8U //cv::Mat testMat; //gradMag_mat.convertTo(testMat,CV_8U,1,0); //cv::imshow("Image Show Window2",testMat); //计算能量线 cv::Mat energyMat(image.rows,image.cols,CV_32F,cv::Scalar(0));//累计能量矩阵 cv::Mat traceMat(image.rows,image.cols,CV_32F,cv::Scalar(0));//能量最小轨迹矩阵 calculateEnergy(gradMag_mat,energyMat,traceMat); //找出最小能量线 cv::Mat minTrace(image.rows,1,CV_32F,cv::Scalar(0));//能量最小轨迹矩阵中的最小的一条的轨迹 getMinEnergyTrace(energyMat,traceMat,minTrace); //显示最小能量线 cv::Mat tmpImage(image.rows,image.cols,image.type()); image.copyTo(tmpImage); for (int i = 0;i < image.rows;i++) { int k = minTrace.at<float>(i,0); tmpImage.at<cv::Vec3b>(i,k)[0] = 0; tmpImage.at<cv::Vec3b>(i,k)[1] = 0; tmpImage.at<cv::Vec3b>(i,k)[2] = 255; } cv::imshow("Image Show Window (缩小)",tmpImage); //删除一列 cv::Mat image2(image.rows,image.cols-1,image.type()); cv::Mat beDeletedLine(image.rows,1,CV_8UC3);//记录被删掉的那一列的值 delOneCol(image,image2,minTrace,beDeletedLine); cv::imshow("Image Show Window",image2); image2.copyTo(outImage); minTrace.copyTo(outMinTrace); beDeletedLine.copyTo(outDeletedLine); }
void ImageTest::testShortImage() { debug(LOG_DEBUG, DEBUG_LOG, 0, "testShortImage() begin"); Image<unsigned short> image2(640, 480); convertImage(image2, *image); CPPUNIT_ASSERT(image2.pixel(13, 15) == ((13 + 15 * 640) % 160) * 256); Image<unsigned char> image3(640,480); convertImage(image3, image2); CPPUNIT_ASSERT(image3 == *image); image3.pixel(14, 15) = 1; CPPUNIT_ASSERT(!(image3 == *image)); debug(LOG_DEBUG, DEBUG_LOG, 0, "testShortImage() end"); }
double run_test_npcr(struct img_info_t *img_info) { cimg_library::CImg<unsigned int> image1(img_info->origin.c_str()); cimg_library::CImg<unsigned int> image2(img_info->encrypted.c_str()); double number_of_pixels = image1.width() * image1.height(); double npcr = 0; // just compare images with the same size, stop if not if (image1.width() != image2.width() || image1.height() != image2.height()) return -1.0; // calculate npcr = (1/number_of_pixel) * sum(D(i,j) * 100 // D(i,j) = 1 , if image1(i,j) != image2(i,j) // D(i,j) = 0 , if image1(i,j) == image2(i,j) cimg_forXY(image1, x, y) { if (image1(x, y, 0, 0) != image2(x, y, 0, 0)) npcr++; } return (npcr * 100) / number_of_pixels; }
void DeconvolveTest::testDisk() { debug(LOG_DEBUG, DEBUG_LOG, 0, "testDisk() begin"); DiskImage image1(ImageSize(256,256), ImagePoint(47,62), 1, 1); ImagePtr iptr = ImagePtr(new Image<double>(image1)); DiskImage image2(ImageSize(256,256), ImagePoint(128,111), 1, 1); BasicDeconvolutionOperator decon(image2); ImagePtr fq = decon(iptr); io::FITSout out("tmp/deconvolve-disk.fits"); out.setPrecious(false); out.write(fq); debug(LOG_DEBUG, DEBUG_LOG, 0, "testDisk() end"); }
int load_png_as_texture(char* filename) { std::vector<unsigned char> image; // width and height will be read from the file at the start // and loaded into these vars unsigned int width = 1, height = 1; unsigned error = lodepng::decode(image, width, height, filename); if (error) { std::cout << "Error loading texture" << std::endl; return (int) error; } // Make some OpenGL properties better for 2D and enable alpha channel. glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glEnable(GL_ALPHA_TEST); if(glGetError() != GL_NO_ERROR) { std::cout << "Error initing GL" << std::endl; return 1; } // Texture size must be power of two for the primitive OpenGL version this is written for. Find next power of two. size_t u2 = 1; while(u2 < width) u2 *= 2; size_t v2 = 1; while(v2 < height) v2 *= 2; // Ratio for power of two version compared to actual version, to render the non power of two image with proper size. // double u3 = (double)width / u2; // double v3 = (double)height / v2; // Make power of two version of the image. std::vector<unsigned char> image2(u2 * v2 * 4); for(size_t y = 0; y < height; y++) for(size_t x = 0; x < width; x++) for(size_t c = 0; c < 4; c++) { image2[4 * u2 * y + 4 * x + c] = image[4 * width * y + 4 * x + c]; } // Enable the texture for OpenGL. glEnable(GL_TEXTURE_2D); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST); //GL_NEAREST = no smoothing glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST); glTexImage2D(GL_TEXTURE_2D, 0, 4, u2, v2, 0, GL_RGBA, GL_UNSIGNED_BYTE, &image2[0]); return 0; }
gboolean media_art_file_to_jpeg (const gchar *filename, const gchar *target, GError **error) { if (max_width_in_bytes < 0) { g_debug ("Not saving album art from file, disabled in config"); return TRUE; } /* TODO: Add resizing support */ /* TODO: Add error reporting */ QFile file (filename); if (!file.open (QIODevice::ReadOnly)) { g_message ("Could not get QFile from file: '%s'", filename); return FALSE; } QByteArray array = file.readAll (); QBuffer buffer (&array); buffer.open (QIODevice::ReadOnly); QImageReader reader (&buffer); if (!reader.canRead ()) { g_message ("Could not get QImageReader from file: '%s', reader.canRead was FALSE", filename); return FALSE; } QImage image1; image1 = reader.read (); if (image1.hasAlphaChannel ()) { QImage image2 (image1.size(), QImage::Format_RGB32); image2.fill (QColor(Qt::black).rgb()); QPainter painter (&image2); painter.drawImage (0, 0, image1); image2.save (QString (target), "jpeg"); } else { image1.save (QString (target), "jpeg"); } return TRUE; }
void MultiVolumeRaycaster::updateResult(DataContainer& dataContainer) { ImageRepresentationGL::ScopedRepresentation image1(dataContainer, p_sourceImage1.getValue()); ImageRepresentationGL::ScopedRepresentation image2(dataContainer, p_sourceImage2.getValue()); ImageRepresentationGL::ScopedRepresentation image3(dataContainer, p_sourceImage3.getValue()); ScopedTypedData<CameraData> camera(dataContainer, p_camera.getValue()); ScopedTypedData<RenderData> geometryImage(dataContainer, p_geometryImageId.getValue(), true); ScopedTypedData<LightSourceData> light(dataContainer, p_lightId.getValue()); std::vector<const ImageRepresentationGL*> images; if (image1) { images.push_back(image1); if (getInvalidationLevel() & INVALID_VOXEL_HIERARCHY1){ _vhm1->createHierarchy(image1, p_transferFunction1.getTF()); validate(INVALID_VOXEL_HIERARCHY1); } } if (image2) { images.push_back(image2); if (getInvalidationLevel() & INVALID_VOXEL_HIERARCHY2){ _vhm2->createHierarchy(image2, p_transferFunction2.getTF()); validate(INVALID_VOXEL_HIERARCHY2); } } if (image3) { images.push_back(image3); if (getInvalidationLevel() & INVALID_VOXEL_HIERARCHY3){ _vhm3->createHierarchy(image3, p_transferFunction3.getTF()); validate(INVALID_VOXEL_HIERARCHY3); } } if (images.size() >= 3 && camera != nullptr) { auto eepp = computeEntryExitPoints(images, camera, geometryImage); dataContainer.addData(p_outputImageId.getValue() + ".entrypoints", eepp.first); dataContainer.addData(p_outputImageId.getValue() + ".exitpoints", eepp.second); auto rc = performRaycasting(dataContainer, images, camera, eepp.first, eepp.second, light); dataContainer.addData(p_outputImageId.getValue(), rc); } else { LDEBUG("No suitable input data found!"); } }
bool compareImages(char* imagePath1, char* imagePath2) { QImage image1(imagePath1); QImage image2(imagePath2); if (image1.isNull()) { qDebug() << "Image 1 couldn't be loaded."; return false; } if (image2.isNull()) { qDebug() << "Image 2 couldn't be loaded."; return false; } return (image1 == image2); }
void ImageTest::testSubimage() { debug(LOG_DEBUG, DEBUG_LOG, 0, "testSubimage() begin"); ImageSize size(10, 12); ImagePoint origin(5, 9); ImageRectangle frame(origin, size); Image<unsigned char> image2(*image, frame); for (int x = 0; x < size.width(); x++) { for (int y = 0; y < size.height(); y++) { unsigned char v1 = image2.pixel(x, y); unsigned char v2 = image->pixel(x + 5, y + 9); unsigned char v3 = (5 + x + 640 * (9 + y)) % 160; CPPUNIT_ASSERT(v1 == v2); CPPUNIT_ASSERT(v2 == v3); } } debug(LOG_DEBUG, DEBUG_LOG, 0, "testSubimage() end"); }
double greplace::gpu::find_statistic(std::vector<std::string> images, double r0, double rf, cv::gpu::CascadeClassifier_GPU & classifier) { std::vector<double> statistic; for (size_t i = 0; i < images.size(); i ++) { std::string image1_location = images[i]; for (size_t j = 0; j < images.size(); j ++) { std::string image2_location = images[j]; cv::gpu::GpuMat image1(cv::imread(image1_location, CV_LOAD_IMAGE_GRAYSCALE)); cv::gpu::GpuMat image2(cv::imread(image2_location, CV_LOAD_IMAGE_GRAYSCALE)); try { cv::gpu::GpuMat face1 = greplace::gpu::find_face(image1, classifier, THRESHOLD); cv::gpu::GpuMat face2 = greplace::gpu::find_face(image2, classifier, THRESHOLD); cv::Mat face1_cpu, face2_cpu, face3_cpu; face1.download(face1_cpu); face2.download(face2_cpu); cv::resize(face2_cpu, face2_cpu, face1_cpu.size()); face2.upload(face2_cpu); cv::gpu::GpuMat face3 = greplace::gpu::blend(face1, face2, r0, rf); face3.download(face3_cpu); cv::imshow("face1", face1_cpu); cv::imshow("face2", face2_cpu); cv::imshow("Blended", face3_cpu); cv::waitKey(10); cv::Mat hist1 = greplace::hist(face1_cpu); cv::Mat hist2 = greplace::hist(face2_cpu); cv::Mat hist3 = greplace::hist(face3_cpu); double s = greplace::hist_correlation(hist1, hist3) + greplace::hist_correlation(hist2, hist3); statistic.push_back(s); } catch (...) { // One of the faces couldn't be found because the angle of the image // is too great for the frontal face classifier } } } return greplace::mean(statistic); }
void MultiVolumeRaycaster::updateProperties(DataContainer& dataContainer) { ImageRepresentationGL::ScopedRepresentation image1(dataContainer, p_sourceImage1.getValue()); ImageRepresentationGL::ScopedRepresentation image2(dataContainer, p_sourceImage2.getValue()); ImageRepresentationGL::ScopedRepresentation image3(dataContainer, p_sourceImage3.getValue()); if (image1) p_transferFunction1.setImageHandle(image1.getDataHandle()); else p_transferFunction1.setImageHandle(DataHandle(nullptr)); if (image2) p_transferFunction2.setImageHandle(image2.getDataHandle()); else p_transferFunction2.setImageHandle(DataHandle(nullptr)); if (image3) p_transferFunction3.setImageHandle(image3.getDataHandle()); else p_transferFunction3.setImageHandle(DataHandle(nullptr)); }
void ImageTest::testYUYVImage() { debug(LOG_DEBUG, DEBUG_LOG, 0, "testYUYVImage() begin"); // test the conversion of an individual pixel YUYV<unsigned char> p((unsigned char)47, 11); unsigned char v; convertPixel(v, p); CPPUNIT_ASSERT(47 == v); // convert a complete image Image<YUYV<unsigned char> > image2(640, 480); convertImage(image2, *image); CPPUNIT_ASSERT(image2.pixel(13, 15).y == (13 + 15 * 640) % 160); // convert to an unsigned short image Image<unsigned char> image3(640, 480); convertImage(image3, image2); CPPUNIT_ASSERT(image3 == *image); image3.pixel(14,15) = 1; CPPUNIT_ASSERT(!(image3 == *image)); debug(LOG_DEBUG, DEBUG_LOG, 0, "testYUYVImage() end"); }
void onDraw(SkCanvas* canvas) override { SkImageInfo info = SkImageInfo::MakeN32Premul(100, 100); SkAutoTUnref<SkSurface> surf(canvas->newSurface(info, nullptr)); if (!surf.get()) { surf.reset(SkSurface::NewRaster(info)); } drawInto(surf->getCanvas()); SkAutoTUnref<SkImage> image(surf->newImageSnapshot()); canvas->drawImage(image, 10, 10, nullptr); SkAutoTUnref<SkSurface> surf2(image->newSurface(info, nullptr)); drawInto(surf2->getCanvas()); // Assert that the props were communicated transitively through the first image SkASSERT(equal(surf->props(), surf2->props())); SkAutoTUnref<SkImage> image2(surf2->newImageSnapshot()); canvas->drawImage(image2, 10 + SkIntToScalar(image->width()) + 10, 10, nullptr); }
bool loadImage(string filename, vector<unsigned char> &m_image, size_t &u2, size_t &v2, double &u3, double &v3, unsigned &width, unsigned &height){ // Load file and decode image. vector<unsigned char> image; unsigned error = lodepng::decode(image, width, height, filename); // If there's an error, display it. if (error != 0) { std::cout << "error " << error << ": " << lodepng_error_text(error) << std::endl; return false; } // Make some OpenGL properties better for 2D and enable alpha channel. glDisable(GL_CULL_FACE); glDisable(GL_DEPTH_TEST); glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); glEnable(GL_BLEND); glDisable(GL_ALPHA_TEST); // Texture size must be power of two for the primitive OpenGL version this is written for. Find next power of two. u2 = 1; while (u2 < width) u2 *= 2; v2 = 1; while (v2 < height) v2 *= 2; // Ratio for power of two version compared to actual version, to render the non power of two image with proper size. u3 = (double)width / u2; v3 = (double)height / v2; // Make power of two version of the image. std::vector<unsigned char> image2(u2 * v2 * 4); for (size_t y = 0; y < height; y++) for (size_t x = 0; x < width; x++) for (size_t c = 0; c < 4; c++) { image2[4 * u2 * y + 4 * x + c] = image[4 * width * y + 4 * x + c]; } m_image = image2; return true; }
std::shared_ptr<TextureImage> FontAdapter_SDL_ttf::AddTextureImage(TextureAtlas* textureAtlas, const std::string& character, int border, std::function<void(Image&)> filter) { SDL_Surface* surface = nullptr; TTF_Font* font = FindFontForCharacter(character); if (font) { SDL_Color color = {255, 255, 255, 255}; surface = TTF_RenderUTF8_Blended(font, character.c_str(), color); } if (!surface) { return textureAtlas->AddTextureImage(Image(4, 4), TextureDiscardability::Discardable); } Image image; image.LoadFromSurface(surface); float scaling = textureAtlas->GetGraphicsContext()->GetCombinedScaling(); int offset = (int)glm::ceil(scaling * border); Image image2(image.GetWidth() + offset * 2, image.GetHeight() + offset * 2); image2.Copy(image, offset, offset); SDL_FreeSurface(surface); image2.SetPixelDensity(scaling); if (filter) filter(image2); std::shared_ptr<TextureImage> textureImage = textureAtlas->AddTextureImage(image2, TextureDiscardability::Discardable); BorderBounds bounds = textureImage->GetBounds(); bounds.inner.min = bounds.outer.min + glm::vec2(offset, offset); bounds.inner.max = bounds.inner.min + glm::vec2(image.GetWidth(), image.GetHeight()); textureImage->SetBounds(bounds); return textureImage; }
void PieceAvailabilityBar::updateImage() { // qDebug() << "updateImageAv"; QImage image2(width() - 2, 1, QImage::Format_RGB888); if (pieces.empty()) { image2.fill(0xffffff); image = image2; update(); return; } std::vector<float> scaled_pieces = intToFloatVector(pieces, image2.width()); // filling image for (unsigned int x = 0; x < scaled_pieces.size(); ++x) { float pieces2_val = scaled_pieces.at(x); image2.setPixel(x, 0, piece_colors[pieces2_val * 255]); } image = image2; }
std::vector<unsigned char> HUD::draw(char* dir){ std::vector<unsigned char> image; unsigned error = lodepng::decode(image, width, height, dir); screenw = width; if(screenw > 1024) screenw = 1024; screenh = height; if(screenh > 768) screenw = 768; u2 = 1;while(u2 < width) u2 *= 2; v2 = 1; while(v2 < height) v2 *= 2; u3 = (double)width / u2; v3 = (double)height / v2; std::vector<unsigned char> image2(u2 * v2 * 4); for(size_t y = 0; y < height; y++) for(size_t x = 0; x < width; x++) for(size_t c = 0; c < 4; c++) image2[4 * u2 * y + 4 * x + c] = image[4 * width * y + 4 * x + c]; return image2; }
void TerrainWeightEditor::DecomposeImageToCanvases(const QImage& image) { QLabel *canvas1 = editor_widget_->findChild<QLabel *>("canvas_1"); QLabel *canvas2 = editor_widget_->findChild<QLabel *>("canvas_2"); QLabel *canvas3 = editor_widget_->findChild<QLabel *>("canvas_3"); QLabel *canvas4 = editor_widget_->findChild<QLabel *>("canvas_4"); assert(canvas1 && canvas2 && canvas3 && canvas4); int width = image.width(); int height = image.height(); QImage::Format format = image.format(); QImage image1(width,height,format); QImage image2(width,height,format); QImage image3(width,height,format); QImage image4(width,height,format); for(int i=0;i<width;i++) { for(int j=0; j<height;j++) { QRgb color = image.pixel(i,j); int alpha = qAlpha(color); int red = qRed(color); int green = qGreen(color); int blue = qBlue(color); image1.setPixel(i,j, QColor(red,red,red).rgba()); image2.setPixel(i,j, QColor(green,green,green).rgba()); image3.setPixel(i,j, QColor(blue,blue,blue).rgba()); image4.setPixel(i,j, QColor(alpha,alpha,alpha).rgba()); } } canvas1->setPixmap(QPixmap::fromImage(image1)); canvas2->setPixmap(QPixmap::fromImage(image2)); canvas3->setPixmap(QPixmap::fromImage(image3)); canvas4->setPixmap(QPixmap::fromImage(image4)); }