jeudi 2 avril 2015

Change Div background image and content on link hover?

i've looked around a bit but most of the solutions are specific to the links background, and not the div's background. I'm trying to understand how to image swap backgrounds for an entire div by hovering over a link in that specific div.


By visiting this page: http://splash.org/, and scrolling down to "Today we served" section, you can hover over the content there and the background image will change.


Thanks!


How to prevent background scrolling in canvas?

I am using ttk.Scrollbar to scroll elements inside a Tkinter.Canvas. Unfortunately a background image of this canvas will also scroll. How can I prevent this?


Here is an example of what I use:



import Tkinter as tk
from ttk import *

# first canvas with scrollbar
root = tk.Tk()
canv1 = tk.Canvas(root, width=200, height=200, bg='green')
sbar = Scrollbar(root, orient="vertical")
sbar.config(command=canv1.yview)
sbar.pack(side="right", fill="y")
canv1.config(yscrollcommand=sbar.set)
canv1.pack(side="right", fill="y")

# background of dirst canvas
photo_content2 = tk.PhotoImage(file = './sample_image.gif')
canv1.create_image(115,300, image=photo_content2)

# scrollable second canvas insode first
canv2 = tk.Canvas(canv1, width=50, height=30, bg='red')
canv2.pack()
canv1.create_window(20,20, window=canv2)
canv1.config(scrollregion=(0,0,300,1000))

root.mainloop()

Please advise me about this Computer Vision task

I have some magnets with images on it. There is only a small set of different images (lets say 20 images), and they will be aligned in fixed chess boar (still not shown in the picture).


computer vision board game yum yum yummy


I have already an algorithm to extract each single magnet card from the board, applying a perspective transformation to the original image to prevent perspective distortion.


I would like to hear your advices in order to detect each single image on the board, I mean, detect if the magnet is: a panda, a rabbit, a dog, a carrot... since my main objective is to analyze the image and extract a matrix containing all the board elements.


My first attempt was very basic: guess the image according to the average color. It was not very robust since there are several images with similar average colors (specially those frozen cards), and light tinting can change color a lot.


Would you be so kind to point me in the right direction to extract a matrix containing all the images on the board? I don't need a specific implementation, but instead the concept of the steps that I should follow or techniques to be aplied to the main image in order to obtain a robust (and not too complex) algorithm.


I'm gonna implement it using OpenCV, but I guess that it would be the same using any other computer vision libraries.


Thanks a lot for your time!


WPF Image RenderOptions.BitmapScalingMode.LowQuality consumes 10x more memory than HighQuality

I have an image which is about 5k x 5k pixels.

The image contains a LayoutTransform with a ScaleTransform.



<Image x:Name="image" Source="{Binding ImageSource, Mode=OneWay}" Width="{Binding ImageWidth, Mode=OneWay}" Height="{Binding ImageHeight, Mode=OneWay}" Visibility="{Binding ImageVisibility, Mode=OneWay}" RenderOptions.BitmapScalingMode="HighQuality" RenderOptions.EdgeMode="Aliased">
<Image.LayoutTransform>
<ScaleTransform ScaleX="{Binding ScaleValue, Mode=OneWay}" ScaleY="{Binding ScaleValue, Mode=OneWay}"/>
</Image.LayoutTransform>
</Image>


Since scaling the image is very slow due to the HighQuality option, I decided to set it to LowQuality during the scaling process. As it turns out the LowQuality option consumes much more memory than HighQuality as you can see in the screenshot.



RenderOptions.SetBitmapScalingMode(image, BitmapScalingMode.LowQuality); //Reduce quality during resize to improve performance (or not :()




The memory peak after setting it to Low is not temporary - it stays until the application is closed. A second or third resize operation has no effect on the peak.



I believe the Image Control caches the image of some sort - not sure though.

I am also familliar with a memory leak which can happen if a BitmapImage is not manually destroyed but I think this is not the problem here since the peak happens during the RenderOption-change.



Any ideas are very much appreciated


EDIT

This is the code I use to load my image:



Stream imageStreamSource = new FileStream(_filePath, FileMode.Open, FileAccess.Read, FileShare.Read);
TiffBitmapDecoder decoder = new TiffBitmapDecoder(imageStreamSource, BitmapCreateOptions.PreservePixelFormat, BitmapCacheOption.OnLoad);

BitmapSource bmSrc = decoder.Frames[0];
bmSrc.Freeze();

ImageSource = bmSrc;


enter image description here


How to show image in an aspx file?

I'm using this <asp:Image ID="UserPicture" runat="server" /> to show image in the aspx file and the code behind looks like this: string imagePath = "~/ProfilePictures/" + UsernameBox.Text; UserPicture.ImageUrl = imagePath;


But after loading the page, the picture won't show up, only the default picture icon appears. Any suggestions how to do it properly? (Maybe resize the image?)


Thanks


How to Swap pixels to mirror an image c++

I have a greyscale image (150 x 200) and I need to mirror it about its vertical axis.


The original image is loaded, then I call my function, then I save the new image under ParrotMirror.png. However with my code the image has not mirrored, could anyone possibly explain what's incorrect about my code? The idea is that pixel element 0 is swapped with 149, and 1 with 148, and 2 with 147 etc...



#include <QCoreApplication>
#include <iostream>
#include "ImageHandle.h"

using namespace std;

int CountBlackPixels (unsigned char PixelGrid[WIDTH][HEIGHT]);

void InvertImage (unsigned char PixelGrid[WIDTH][HEIGHT]);

void ReducePixelLevel (unsigned char PixelGrid[WIDTH][HEIGHT]);

void MirrorImage (unsigned char PixelGrid[WIDTH][HEIGHT]);


int main(int argc, char *argv[])

{
QCoreApplication a(argc, argv);

unsigned char PixelGrid[WIDTH][HEIGHT]; // Image loaded from file

// If the file "Parrot.png" cannot be loaded ...
if (!loadImage(PixelGrid, "Parrot.png"))
{
// Display an error message
cout << "Error loading file \"Parrot.png\"" << endl;
}

MirrorImage(PixelGrid);
{
if (saveImage(PixelGrid, "ParrotMirror.png"))
{
cout << "\nFile \"ParrotMirror.png\" saved successfully" << endl;
}
else
{
cout << "\nCould not save \"ParrotMirror.png\"" << endl;
}

}

return a.exec();
}

void MirrorImage (unsigned char PixelGrid[WIDTH][HEIGHT])
{

for (int row = 0; row < WIDTH; ++row)
{
int swapRow = WIDTH - 1 - row; // Mirror pixel

int col = 0;

PixelGrid[row][col] = PixelGrid[swapRow][col];

}
}


I have only shown parts of my code relevant to the question, the reason the original image must be reloaded is because there are other functions modifying the image and saving too.


Upload an image to server and resize with Perl+GD

I upload image by CGI. Then I need recize it and save to server.



my $q=new CGI;
my $photo=$q->param('photo'); # it is uploaded image by html form


Then I don't understand how to convert $photo for GD needed type?



$image = GD::Image->newFromJpeg($photo); # create a new image


Then I recize it:



my ($ox, $oy) = $image->getBounds();
my ($nx, $ny) = (800, 600);
my $outimage = new GD::Image($nx, $ny);
$outimage->copyResized($image, 0, 0, 0, 0, $nx, $ny, $ox, $oy);