Page 1 of 1

Compare pictures

Posted: 2014-03-11T03:02:50-07:00
by Dzhoko
Hello community, Maybe you can help me ?

I want to compare two pictures with visual studio. I have added "Magick++.h".

How can i realize this command with c++?

Code: Select all

compare -metric AE Image1 Image2 info

Re: Compare pictures

Posted: 2014-03-11T15:28:23-07:00
by dlemstra
It should be something like this:

Code: Select all

Image Image1("Image1");
Image Image2("Image2");
double result;

result=Image1.compare(Image2,AbsoluteErrorMetric); 

Re: Compare pictures

Posted: 2014-03-24T01:53:50-07:00
by Dzhoko
Thanks, I have just one little question, how can I add in c++ "-fuzz", that my command looked so:

Code: Select all

compare -metric AE -fuzz 10% Image1 Image2 info:

Re: Compare pictures

Posted: 2014-03-24T03:56:52-07:00
by dlemstra
Fuzz is called colorFuzz in Magick++. You need to see this to a value between 0 and QuantumMax. For a Q16 build you could use 6553 as the value.

Re: Compare pictures

Posted: 2014-03-24T04:46:19-07:00
by Dzhoko
Thanks

Re: Compare pictures

Posted: 2014-03-25T03:14:11-07:00
by Dzhoko
I have one more question, how can I convert HBITMAP (or Bitmap) in Magick::Image?
here is my code:

Code: Select all

...
BitBlt(memdc, 0, 0, width, height, scrdc, 0, 0 ,SRCCOPY);
HBITMAP handle=(HBITMAP)SelectObject(memdc, membit);
Gdiplus::Bitmap bitmap(handle, NULL);
Magick::Image img;
...
how I get this picture in img without save it on hard disk?

Re: Compare pictures

Posted: 2014-03-26T01:56:09-07:00
by Dzhoko
Or how can I take a screen shot from open window with magick++. I have used GDIPlus library for this, but I can not save the picture in Magick::Image format, here is my code

Code: Select all

 #include "stdafx.h"
 #include <windows.h>
 #include <stdio.h>
 #include <iostream>
 #include <fstream>
 #include <gdiplus.h>

 using namespace std;

 #pragma comment(lib, "GdiPlus.lib")
 using namespace Gdiplus; 

 static const GUID png = 
 { 0x557cf406, 0x1a04, 0x11d3, { 0x9a, 0x73, 0x00, 0x00, 0xf8, 0x1e, 0xf3, 0x2e } };


 int main()
 {
     GdiplusStartupInput gdiplusStartupInput;
     ULONG_PTR gdiplusToken;
     GdiplusStartup(&gdiplusToken, &gdiplusStartupInput, NULL);

     HDC scrdc, memdc;
     HBITMAP membit;
   
     HWND hWnd = FindWindow(_T("VGA2USB_MainWindow"), NULL);
     scrdc = GetDC(hWnd);
     
     int Height, Width;
     
     RECT rect;
    (GetWindowRect(hWnd,&rect));
	
     int width=rect.right-rect.left;
     int height = rect.bottom - rect.top;
     memdc = CreateCompatibleDC(scrdc);
     membit = CreateCompatibleBitmap(scrdc, width, height);
     SelectObject(memdc, membit);
	 
     BitBlt(memdc, 0, 0, width, height, scrdc, 0, 0, SRCCOPY);
     HBITMAP hBitmap;
     hBitmap =(HBITMAP) SelectObject(memdc, membit);
     Gdiplus::Bitmap bitmap(hBitmap, NULL);
     bitmap.Save(L"C:\screen.jpg", &png);

     DeleteObject(hBitmap);

	 return 0;
 }

Is it possible to make the same function with magick++?

Sure I can read screen.jpg with Magick::Image img("screen.jpg"), but I need to take a screen shot and save it in "img", without saving it to hard disk!
Can I make the screen shot function with magick++ or can I convert bitmap in Image::Magick format?
Thanks.

Re: Compare pictures

Posted: 2014-03-30T04:31:16-07:00
by dlemstra
We have added a new feature to the Windows distribution of ImageMagick. You can take a screen shot of your monitor with the following code:

Code: Select all

Image screen("screenshot:")
// And if you have multiple monitors:
Image first("screenshot:[0]")
Image second("screenshot:[1]")
This feature will be available in ImageMagick 6.8.9-0.

Re: Compare pictures

Posted: 2014-04-12T16:49:50-07:00
by snibgo
Neat. From the command line, "-list format" shows this as "r--" but:

Code: Select all

F:\web\im>%IMG689%convert screenshot: r.png

convert.exe: no images defined `r.png' @ error/convert.c/ConvertImageCommand/3161.

Re: Compare pictures

Posted: 2014-04-13T00:57:35-07:00
by dlemstra
Thank you for reporting this Snibgo, it will be fixed in the next release.