void PatchWarper::updatePatch() { //ProfileSection s("updatePatch"); { //For some reason this is very slow in some machines when multi-threading. //cv::warpAffine(*mSourceImage, mPatch, mWarpMatrix, cv::Size(kPatchSize, kPatchSize), cv::INTER_LINEAR | cv::WARP_INVERSE_MAP); //Manual interpolation auto &srcImg = *mSourceImage; mPatch.create(kPatchSize, kPatchSize); //Check corners if (mWarpedCorners[0].x >= 0 && mWarpedCorners[0].y >= 0 && mWarpedCorners[0].x < srcImg.cols-1 && mWarpedCorners[0].y < srcImg.rows-1 && mWarpedCorners[1].x >= 0 && mWarpedCorners[1].y >= 0 && mWarpedCorners[1].x < srcImg.cols-1 && mWarpedCorners[1].y < srcImg.rows-1 && mWarpedCorners[2].x >= 0 && mWarpedCorners[2].y >= 0 && mWarpedCorners[2].x < srcImg.cols-1 && mWarpedCorners[2].y < srcImg.rows-1 && mWarpedCorners[3].x >= 0 && mWarpedCorners[3].y >= 0 && mWarpedCorners[3].x < srcImg.cols-1 && mWarpedCorners[3].y < srcImg.rows-1) { //Interpolate for (int v = 0; v < kPatchSize; ++v) { auto patchRow = mPatch[v]; float m12yc = mWarpMatrix(0, 1)*v + mWarpMatrix(0, 2); float m22yc = mWarpMatrix(1, 1)*v + mWarpMatrix(1, 2); for (int u = 0; u < kPatchSize; ++u) { float srcX = mWarpMatrix(0, 0)*u + m12yc; float srcY = mWarpMatrix(1, 0)*u + m22yc; int srcXi = (int)srcX; int srcYi = (int)srcY; float alphaX = srcX - srcXi; float alphaY = srcY - srcYi; float rowMixLeft = srcImg(srcYi, srcXi)*(1.0f - alphaY) + srcImg(srcYi + 1, srcXi)*alphaY; float rowMixRight = srcImg(srcYi, srcXi + 1)*(1.0f - alphaY) + srcImg(srcYi + 1, srcXi + 1)*alphaY; patchRow[u] = (uchar)(rowMixLeft*(1.0f - alphaX) + rowMixRight*alphaX); } } } } mLastWarpMatrix = mWarpMatrix; for(int i=0; i<4; i++) mLastWarpedCorners[i] = mWarpedCorners[i]; }
void SkBaseDevice::drawSpriteWithFilter(const SkDraw& draw, const SkBitmap& bitmap, int x, int y, const SkPaint& paint) { SkImageFilter* filter = paint.getImageFilter(); SkASSERT(filter); SkIPoint offset = SkIPoint::Make(0, 0); SkMatrix matrix = *draw.fMatrix; matrix.postTranslate(SkIntToScalar(-x), SkIntToScalar(-y)); const SkIRect clipBounds = draw.fRC->getBounds().makeOffset(-x, -y); SkAutoTUnref<SkImageFilterCache> cache(this->getImageFilterCache()); SkImageFilter::Context ctx(matrix, clipBounds, cache.get()); sk_sp<SkSpecialImage> srcImg(SkSpecialImage::internal_fromBM(bitmap, &this->surfaceProps())); if (!srcImg) { return; // something disastrous happened } sk_sp<SkSpecialImage> resultImg(filter->filterImage(srcImg.get(), ctx, &offset)); if (resultImg) { SkPaint tmpUnfiltered(paint); tmpUnfiltered.setImageFilter(nullptr); SkBitmap resultBM; if (resultImg->internal_getBM(&resultBM)) { // TODO: add drawSprite(SkSpecialImage) to SkDevice? (see skbug.com/5073) this->drawSprite(draw, resultBM, x + offset.x(), y + offset.y(), tmpUnfiltered); } } }
void Launcher_page::cpWallpaper(QString extWallpaperPath) { /* 用bash脚本拷贝壁纸 QStringList strList; QString command = Global::mingw64 + "\\bash.exe"; strList << "test.sh" << Global::mingw64 << Global::srcPath << extWallpaperPath << "2"; qDebug() << command; // strList << Global::mingw64 << Global::prj_home_path + "\\bin\\bash_helper.sh"<< Global::srcPath << extWallpaperPath << "2"; qDebug() << strList; p->start("bash", strList); */ QDir *extDir = new QDir(extWallpaperPath); QStringList fileList = extDir->entryList(); QString pathWallpaperOverlay = Global::srcPath + "/" + Global::overlayPath + "/packages/apps/Launcher3/res/drawable-nodpi"; QString wallpaperXml = Global::srcPath + "/packages/apps/Launcher3/res/values/wallpapers.xml"; QDir *overlayDir = new QDir(pathWallpaperOverlay); if(fileList.length() > 2) { if(!overlayDir->mkpath(pathWallpaperOverlay)) { qDebug() << "mkpath fail.. " << pathWallpaperOverlay; QMessageBox::critical(this, tr("错误警告 : "), tr("创建目录") + pathWallpaperOverlay + tr("失败,请检查目标路径是否有可写权限,或目标路径被文件浏览器打开")); return; } for(int i = 2; i < fileList.length(); i++) { QStringList nameList = fileList[i].split("."); QImage srcImg(extWallpaperPath + "/" + fileList[i]); qDebug() << extWallpaperPath + "/" + fileList[i]; QImage smlImg = srcImg.scaled(200,200); if(!smlImg.save(pathWallpaperOverlay + "/" + nameList[0] + "_small." + nameList[1])) { qDebug() << "small image save fail"; } QFile::copy(extWallpaperPath + "/" + fileList[i], pathWallpaperOverlay +"/" + fileList[i]); qDebug() << pathWallpaperOverlay + "/" + nameList[0] + "_small." + nameList[1]; textHelper.addWallpaperXml(wallpaperXml, nameList[0]); } }else { QMessageBox::information(this, tr("提示~~~"), tr("壁纸文件夹内空。。。。。")); } }
void SiftGui::loadImage() { QStringList filename = QFileDialog::getOpenFileNames(this, "Please select an input image file.", ".", "*.jpg *.png *.bmp *.tiff *.pgm"); foreach(QString s, filename) { // skip images already loaded if(_infilelist.contains(s)) continue; QImage srcImg(s); ImageViewer* srcViewer = new ImageViewer(_imageContainer); srcViewer->setImage(srcImg); srcViewer->setWindowTitle(s); srcViewer->setSignature(s); connect(srcViewer, SIGNAL(sig_viewerClosed(QString)), this, SLOT(handleViewerClosed(QString))); _imageContainer->addSubWindow(srcViewer); srcViewer->show(); _infilelist.push_back(s); } }
void VehicleDetectionSystem::update(const cv::Mat* a_imageFrame, std::shared_ptr<std::vector<std::shared_ptr<DetectedVehicle>>> verifiedVehicles, double timeStamp) { //clock_t timeBegin = clock(); // Save a copy of the source image so that we don't change the original one cv::Mat srcImg(a_imageFrame->size(), a_imageFrame->type()); a_imageFrame->copyTo(srcImg); //cv::Mat srcImg = a_imageFrame->clone(); cv::resize(srcImg, srcImg, cv::Size(m_windowWidth, m_windowHeight), 0, 0, cv::INTER_CUBIC); cv::Mat outputImg(srcImg.size(), srcImg.type()); srcImg.copyTo(outputImg); //cv::Mat outputImg = srcImg.clone(); //GaussianBlur(srcImg, srcImg, cv::Size(3,3), 1); // Extract the sub image of the region of interest cv::Mat imageROI = srcImg(m_regionOfInterest); m_haarClassifier.detectMultiScale(imageROI, m_potentialVehicles); //haarClassifier.detectMultiScale(imageROI, detectedVehicles, 1.03, 3, 0 | CASCADE_FIND_BIGGEST_OBJECT, Size(10, 10), Size(150, 150)); //haarClassifier.detectMultiScale(imageROI, detectedVehicles, 1.03, 1, 0, Size(10, 10), Size(150, 150)); //haarClassifier.detectMultiScale(imageROI, detectedVehicles, 1.1, 3, 0 | CASCADE_FIND_BIGGEST_OBJECT, Size(20, 20), Size(150, 150)); //clock_t timeHaar = clock(); //std::cout << " Detected " << m_potentialVehicles.size() << " potential vehicles\n"; cv::Mat subImage; std::cout << "Potential #vehicles: " << m_potentialVehicles.size() << std::endl; for (size_t i = 0; i < m_potentialVehicles.size(); i++) { //cout << "Inside for loop \n"; cv::Rect r = m_potentialVehicles[i]; r.y += m_roiTop; //cv::imshow("Debug", srcImg(r)); //cv::waitKey(0); //cv::Mat featureMat(nrOfFeatures, 1, CV_32FC1, featureVector); subImage = cv::Mat(srcImg(r).size(), srcImg(r).type()); srcImg(r).copyTo(subImage); //subImage = srcImg(r).clone(); float result = m_ann.doClassification(&subImage); std::cout << "ann result: " << result << std::endl; bool saveImages = false; std::string saveImgPath = "tmp_img/"; if (result > 0) { // if this subimage gets verified by SVM, draw green cv::rectangle(outputImg, r, cv::Scalar(0,255,0)); std::shared_ptr<DetectedVehicle> detectedVehicle( new DetectedVehicle(r, timeStamp)); verifiedVehicles->push_back(detectedVehicle); if (saveImages) { std::string imgFileName = saveImgPath + "pos" + std::to_string(m_imgCounter) + ".jpg"; imwrite(imgFileName, subImage); m_imgCounter++; } } else { // otherwise, if not verified, draw gray cv::rectangle(outputImg, r, cv::Scalar(0,0,255)); if (saveImages) { std::string imgFileName = saveImgPath + "neg" + std::to_string(m_imgCounter) + ".jpg"; imwrite(imgFileName, subImage); m_imgCounter++; } } //std::cout << "ANN response: " << result << "\n"; //cv::imshow("Debug", subImage); //cv::waitKey(10); //cv::rectangle(outputImg, r, cv::Scalar(0,255,0)); subImage.release(); } //clock_t timeAnn = clock(); //float f_timeHaar = (float) (timeHaar-timeBegin)/CLOCKS_PER_SEC; //float f_timeAnn = (float) (timeAnn-timeHaar)/CLOCKS_PER_SEC; //std::cout << " (timeHaar, timeAnn): (" << f_timeHaar << ", " << f_timeAnn << ")\n"; // Create the window //cv::imshow("VehicleDetectionSystem", outputImg); //cv::moveWindow("VehicleDetectionSystem", 100, 100); //cv::waitKey(10); subImage.release(); imageROI.release(); outputImg.release(); srcImg.release(); }
void ThemePreviewer::renderPreview(const Theme& newSettings) { this->theme = newSettings; QPixmap thumbnailPixmap(this->width, this->height); QPainter painter(&thumbnailPixmap); // First, paint the background image, if any. if (PictureAspectNone != theme.getBackgroundImageAspect()) { QImage destImg; // Load the background image from the file, if available, and zoom. if ( !theme.getBackgroundImageUrl().isNull() && !theme.getBackgroundImageUrl().isEmpty()) { QImage srcImg(theme.getBackgroundImageUrl()); destImg = srcImg.scaled ( thumbnailPixmap.size(), Qt::KeepAspectRatioByExpanding, Qt::SmoothTransformation ); } // Draw the image. painter.fillRect ( thumbnailPixmap.rect(), QBrush(theme.getBackgroundColor()) ); if (!destImg.isNull()) { painter.drawImage ( (thumbnailPixmap.width() - destImg.width()) / 2, (thumbnailPixmap.height() - destImg.height()) / 2, destImg ); } } // If there's no background image, then just fill the background color. else { QColor bgColor = theme.getBackgroundColor(); if (EditorAspectStretch == theme.getEditorAspect()) { bgColor = theme.getEditorBackgroundColor(); } painter.fillRect ( thumbnailPixmap.rect(), bgColor.rgb() ); } // Next, draw the "editor" background. int w = 2 * width / 3; int h = height / 4; int x = (width) / 3 - 3; int y = (3 * height) / 4 - 3; painter.setRenderHint(QPainter::Antialiasing); painter.setPen(Qt::NoPen); painter.setBrush(QBrush(theme.getEditorBackgroundColor())); if (EditorAspectCenter == theme.getEditorAspect()) { if (EditorCornersSquare == theme.getEditorCorners()) { painter.drawRect(x, y, w, h); } else if (EditorCornersRounded == theme.getEditorCorners()) { int cornerRadius = 5.0 * height / 100.0; if (cornerRadius > 10.0) { cornerRadius = 10.0; } painter.drawRoundedRect(x, y, w, h, cornerRadius, cornerRadius); } } else { painter.drawRect(0, 0, width, height); } // Now draw a circle in the "editor" background for each of the text colors. int radius = (h / 4); int xoffset = w / 3; int cx1 = x + (xoffset / 2); int cx2 = cx1 + xoffset; int cx3 = cx2 + xoffset; int cy = y + (h / 2); painter.setBrush(QBrush(theme.getDefaultTextColor())); painter.drawEllipse(QPoint(cx1, cy), radius, radius); painter.setBrush(QBrush(theme.getMarkupColor())); painter.drawEllipse(QPoint(cx2, cy), radius, radius); painter.setBrush(QBrush(theme.getLinkColor())); painter.drawEllipse(QPoint(cx3, cy), radius, radius); painter.end(); thumbnailPreviewIcon = QIcon(thumbnailPixmap); }
/* * aSrc is the current frame being drawn, * aDst is the composition frame where the current frame is drawn into. * aSrcRect is the size of the current frame, and the position of that frame * in the composition frame. */ nsresult imgContainer::DrawFrameTo(gfxIImageFrame *aSrc, gfxIImageFrame *aDst, nsIntRect& aSrcRect) { NS_ENSURE_ARG_POINTER(aSrc); NS_ENSURE_ARG_POINTER(aDst); nsIntRect dstRect; aDst->GetRect(dstRect); // According to both AGIF and APNG specs, offsets are unsigned if (aSrcRect.x < 0 || aSrcRect.y < 0) { NS_WARNING("imgContainer::DrawFrameTo: negative offsets not allowed"); return NS_ERROR_FAILURE; } // Outside the destination frame, skip it if ((aSrcRect.x > dstRect.width) || (aSrcRect.y > dstRect.height)) { return NS_OK; } gfx_format format; aSrc->GetFormat(&format); if (format == gfxIFormats::PAL || format == gfxIFormats::PAL_A1) { // Larger than the destination frame, clip it PRInt32 width = PR_MIN(aSrcRect.width, dstRect.width - aSrcRect.x); PRInt32 height = PR_MIN(aSrcRect.height, dstRect.height - aSrcRect.y); // The clipped image must now fully fit within destination image frame NS_ASSERTION((aSrcRect.x >= 0) && (aSrcRect.y >= 0) && (aSrcRect.x + width <= dstRect.width) && (aSrcRect.y + height <= dstRect.height), "imgContainer::DrawFrameTo: Invalid aSrcRect"); // clipped image size may be smaller than source, but not larger NS_ASSERTION((width <= aSrcRect.width) && (height <= aSrcRect.height), "imgContainer::DrawFrameTo: source must be smaller than dest"); if (NS_FAILED(aDst->LockImageData())) return NS_ERROR_FAILURE; // Get pointers to image data PRUint32 size; PRUint8 *srcPixels; gfx_color *colormap; gfx_color *dstPixels; aSrc->GetImageData(&srcPixels, &size); aDst->GetImageData((PRUint8**)&dstPixels, &size); aSrc->GetPaletteData(&colormap, &size); if (!srcPixels || !dstPixels || !colormap) { aDst->UnlockImageData(); return NS_ERROR_FAILURE; } // Skip to the right offset dstPixels += aSrcRect.x + (aSrcRect.y * dstRect.width); if (format == gfxIFormats::PAL) { for (PRInt32 r = height; r > 0; --r) { for (PRInt32 c = 0; c < width; c++) { dstPixels[c] = colormap[srcPixels[c]]; } // Go to the next row in the source resp. destination image srcPixels += aSrcRect.width; dstPixels += dstRect.width; } } else { // With transparent source, skip transparent pixels for (PRInt32 r = height; r > 0; --r) { for (PRInt32 c = 0; c < width; c++) { const PRUint32 color = colormap[srcPixels[c]]; if (color) dstPixels[c] = color; } // Go to the next row in the source resp. destination image srcPixels += aSrcRect.width; dstPixels += dstRect.width; } } aDst->UnlockImageData(); return NS_OK; } nsCOMPtr<nsIImage> srcImg(do_GetInterface(aSrc)); nsRefPtr<gfxPattern> srcPatt; srcImg->GetPattern(getter_AddRefs(srcPatt)); nsCOMPtr<nsIImage> dstImg(do_GetInterface(aDst)); nsRefPtr<gfxASurface> dstSurf; // Note: dstImage has LockImageData() called on it above, so it's safe to get // the surface. dstImg->GetSurface(getter_AddRefs(dstSurf)); gfxContext dst(dstSurf); dst.Translate(gfxPoint(aSrcRect.x, aSrcRect.y)); dst.Rectangle(gfxRect(0, 0, aSrcRect.width, aSrcRect.height), PR_TRUE); // first clear the surface if the blend flag says so PRInt32 blendMethod; aSrc->GetBlendMethod(&blendMethod); if (blendMethod == imgIContainer::kBlendSource) { gfxContext::GraphicsOperator defaultOperator = dst.CurrentOperator(); dst.SetOperator(gfxContext::OPERATOR_CLEAR); dst.Fill(); dst.SetOperator(defaultOperator); } dst.SetPattern(srcPatt); dst.Paint(); return NS_OK; }