OpenCV better detection of red color?

In HSV space, the red color wraps around 180. So you need the H values to be both in [0,10] and [170, 180]. Try this: #include <opencv2\opencv.hpp> using namespace cv; int main() { Mat3b bgr = imread(“path_to_image”); Mat3b hsv; cvtColor(bgr, hsv, COLOR_BGR2HSV); Mat1b mask1, mask2; inRange(hsv, Scalar(0, 70, 50), Scalar(10, 255, 255), mask1); inRange(hsv, Scalar(170, … Read more

Searching for a way to do bitwise XOR on images

ImageMagick can do it, although it’s a bit convoluted. One way is: convert img1 img2 -fx “(((255*u)&(255*(1-v)))|((255*(1-u))&(255*v)))/255” img_out (img1,img2,img_out are the two input and single output file names respectively). Explanation It’s a bit ugly (I’m sure someone with more ImageMagick-fu than me could clean it up but it works like this: -fx “xxx” basically says … Read more

How to find the dominant/most common color in an image?

Here’s code making use of Pillow and Scipy’s cluster package. For simplicity I’ve hardcoded the filename as “image.jpg”. Resizing the image is for speed: if you don’t mind the wait, comment out the resize call. When run on this sample image, it usually says the dominant colour is #d8c865, which corresponds roughly to the bright … Read more

imagemagick resizing and quality PNG

You can further reduce quality of PNG by using posterization: https://github.com/pornel/mediancut-posterizer (Mac GUI) This is a lossy operation that allows zlib to compress better. Convert image to PNG8 using pngquant. It reduces images to 256 colors, so quality depends on the type of image, but pngquant makes very good palettes, so you might be surprised … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)