Compare pictures

Magick++ is an object-oriented C++ interface to ImageMagick. Use this forum to discuss, make suggestions about, or report bugs concerning Magick++.
Post Reply
Dzhoko
Posts: 7
Joined: 2014-03-11T02:20:03-07:00
Authentication code: 6789

Compare pictures

Post 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
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Compare pictures

Post by dlemstra »

It should be something like this:

Code: Select all

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

result=Image1.compare(Image2,AbsoluteErrorMetric); 
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
Dzhoko
Posts: 7
Joined: 2014-03-11T02:20:03-07:00
Authentication code: 6789

Re: Compare pictures

Post 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:
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Compare pictures

Post 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.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
Dzhoko
Posts: 7
Joined: 2014-03-11T02:20:03-07:00
Authentication code: 6789

Re: Compare pictures

Post by Dzhoko »

Thanks
Dzhoko
Posts: 7
Joined: 2014-03-11T02:20:03-07:00
Authentication code: 6789

Re: Compare pictures

Post 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?
Dzhoko
Posts: 7
Joined: 2014-03-11T02:20:03-07:00
Authentication code: 6789

Re: Compare pictures

Post 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.
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Compare pictures

Post 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.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: Compare pictures

Post 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.
snibgo's IM pages: im.snibgo.com
User avatar
dlemstra
Posts: 1570
Joined: 2013-05-04T15:28:54-07:00
Authentication code: 6789
Contact:

Re: Compare pictures

Post by dlemstra »

Thank you for reporting this Snibgo, it will be fixed in the next release.
.NET + ImageMagick = Magick.NET https://github.com/dlemstra/Magick.NET, @MagickNET, Donate
Post Reply