GithubHelp home page GithubHelp logo

nitinramadoss / image_compare Goto Github PK

View Code? Open in Web Editor NEW
26.0 26.0 9.0 3.38 MB

Dart package for comparing images. Find the difference between two images by using a variety of image comparison techniques.

License: BSD 3-Clause "New" or "Revised" License

Dart 100.00%
algorithm average-hash-algorithm dart euclidean-algorithm flutter image image-processing imagecomparison perceptual-hashing rgb-histogram

image_compare's People

Contributors

krlaa avatar nitinramadoss avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

image_compare's Issues

Make _getImageFromDynamic public

Thank you for the awesome package.
I used it for my tool to quickly find the icon from the screenshot.
But the screenshot is not transparent background like the icon, so I need a way to make these images have the same background.

It's nice if you can public _getImageFromDynamic so I can use it to get Image and apply some filter before comparing.

'image_compare' package in not compatible with latest 'image' package

Latest 'image_compare' package version 1.1.2 is compatible only with older version of 'image' package 3.3.0 whereas the latest version of 'image' package is 4.1.4.

Terminal after running 'flutter pub get':
Resolving dependencies... (1.5s)
Because image_compare 1.1.2 depends on image ^3.0.0 and no versions of image_compare match >1.1.2 <2.0.0, image_compare ^1.1.2 requires image ^3.0.0.
So, because projectname depends on both image ^4.0.17 and image_compare ^1.1.2, version solving failed.

You can try the following suggestion to make the pubspec resolve:

  • Consider downgrading your constraint on image: flutter pub add image:^3.3.0

Image Class is not supported

im using your library and passing 2 images says that
"flutter: Unsupported operation: The source, Image, passed in is unsupported"
which is funny since it says they are Image class any idea?

code

`var render = await this.widget.picture.toImage();
  try {

    print(render.runtimeType); // prints Image

    var result = await compareImages(
        src1: render,
        src2: render,
        algorithm: ChiSquareDistanceHistogram());

    print('The difference between images is: ${result * 100}%');
  } catch (e) {
    print(e);
  }`

Cannot open file, path = '..assets/images/bunny.jpg' (OS Error: No such file or directory, errno = 2) , EVEN THOUGH I HAVE TESTED IMAGES FROM TESTED FOLDER IT IS SHOWING AND READING IN IMAGE.FILE

ERROR
E/flutter (23739): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PathNotFoundException: Cannot open file, path = '..assets/images/bunny.jpg' (OS Error: No such file or directory, errno = 2)

CODE
import 'dart:typed_data';
//tested working
import 'package:flutter/material.dart';
import 'dart:io';
import 'package:image_compare/image_compare.dart';
//https://pub.dev/packages/image_compare
class testScreen extends StatefulWidget {
// const testScreen({Key? key}) : super(key: key);

@OverRide
State createState() => testScreenState();
}

class testScreenState extends State {
@OverRide
Widget build(BuildContext context) {
return Scaffold(
body: Container(
child: Center(
child: Center(
child: Padding(
padding: const EdgeInsets.only(top: 60),
child: Column(

        children: <Widget>[
          IconButton(onPressed: () async{

            ImageCompare();


          }, icon: Center(child: Icon(Icons.ac_unit)) ),


          Image.asset(
            'assets/images/bunny.jpg',
            height: 400,
            width: 400,
          ),



          
          
        ],

      ),
    ),
  ),
),

),
);
}
}

//this is one image compare async mehod
void ImageCompare() async{

// var url1 = Uri.parse('https://www.tompetty.com/sites/g/files/g2000007521/f/sample_01.jpg');
// var url2 = Uri.parse('https://www.tompetty.com/sites/g/files/g2000007521/f/sample_01.jpg');
// var url2 = 'https://fujifilm-x.com/wp-content/uploads/2019/08/x-t30_sample-images03.jpg';

//jpg ko recognize kar reha ha , jpg pa response da reha ha
// png ko koi algrithm bh recognize nai kar reha

//working
var a = Uri.parse('https://fujifilm-x.com/wp-content/uploads/2019/08/x-t30_sample-images03.jpg');
var aS = Uri.parse('https://fujifilm-x.com/wp-content/uploads/2019/08/x-t30_sample-images03.jpg');
var c = Uri.parse('https://hs.sbcounty.gov/cn/Photo%20Gallery/Sample%20Picture%20-%20Koala.jpg');

//not working
var d_discard_png_not_recognizing = Uri.parse('https://github.com/nitinramadoss/image_compare/blob/main/images/seven2.PNG');
var e_discard_png_not_recognizing = Uri.parse('https://github.com/nitinramadoss/image_compare/blob/main/images/seven.PNG');

//not working (because ya temporary directory ( sxGKm5wK ) bna reha ha jis ke wejha sa direct image detect nai kar reha )

dynamic f = Uri.parse('https://i.postimg.cc/sxGKm5wK/bunny.jpg');
dynamic g = Uri.parse('https://i.postimg.cc/kMVdzZHY/deer.jpg');

// https://images.unsplash.com/photo-1592029383200-73fb26a5b925?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1160&q=80

//unsplash Working (because ya temporary directory nai bna reha ha jis ke wejha sa direct image detect kar reha)
var unsplash_pic_1 = Uri.parse('https://images.unsplash.com/photo-1592029383200-73fb26a5b925?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1160&q=80');
var unsplash_pic_1_same_compare = Uri.parse('https://images.unsplash.com/photo-1592029383200-73fb26a5b925?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1160&q=80');
var unsplash_pic_2 = Uri.parse('https://images.unsplash.com/photo-1613681230409-6423a38c43e1?ixlib=rb-4.0.3&ixid=MnwxMjA3fDB8MHxwaG90by1wYWdlfHx8fGVufDB8fHx8&auto=format&fit=crop&w=1742&q=80');

//google image test

//not working (because ya temporary directory ( sxGKm5wK ) bna reha ha jis ke wejha sa direct image detect nai kar reha )
var google_drive_image_t1 = Uri.parse('https://drive.google.com/file/d/1PkTtgQTeNi0Ss0GSeYBaK82rYEs_ed4O');
var google_drive_image_t2 = Uri.parse('https://drive.google.com/file/d/1PkTtgQTeNi0Ss0GSeYBaK82rYEs_ed4O');

//firebase test (I dont know why it is working but it is giving response )

//https://firebasestorage.googleapis.com/v0/b/face-liveness-detector.appspot.com/o/images%2FuserID%3A1%3Arehan?alt=media&token=8b214d4c-cf8a-4134-8b2e-91355f4b5c6a
var firebase_image_t1 = Uri.parse('https://firebasestorage.googleapis.com/v0/b/face-liveness-detector.appspot.com/o/images%2FuserID%3A1%3Arehan?alt=media&token=8b214d4c-cf8a-4134-8b2e-91355f4b5c6a');
var firebase_image_t2 = Uri.parse('https://firebasestorage.googleapis.com/v0/b/face-liveness-detector.appspot.com/o/images%2FuserID%3A12%3Awajahat?alt=media&token=3a9b3e61-0cf7-474f-93cc-9db99a06e1b7');
var firebase_image_t2_different_expression = Uri.parse('https://firebasestorage.googleapis.com/v0/b/face-liveness-detector.appspot.com/o/images%2FuserID%3A1%3Arehan?alt=media&token=8b214d4c-cf8a-4134-8b2e-91355f4b5c6a');
var firebase_image_t1_same = Uri.parse('https://firebasestorage.googleapis.com/v0/b/face-liveness-detector.appspot.com/o/images%2FuserID%3A1%3Arehan?alt=media&token=8b214d4c-cf8a-4134-8b2e-91355f4b5c6a');

//File tesing
//
//this format not working
// String? imagePath1='- assets/images/bunny.jpg';
// String? imagePath2='- assets/images/deer.jpg';

//not working
// String? imagePath1_format_diferent='images/bunny.jpg';
// String? imagePath2_format_diferent='images/bunny.jpg';

//not working
// var file_1 = File('$imagePath1_format_diferent');
// var file_2 = File('$imagePath2_format_diferent');

// print(' Ya rahe file nicha liabrary support nai kar rahe $file_1');

// Calculate euclidean color distance between two images
// EuclideanColorDistance( ignoreAlpha: true ) - tested - problem : diference problem
// File

/*
Image.asset(
'assets/images/bunny.jpg',
height: 400,
width: 400,
);*/

File File1 = File('..assets/images/bunny.jpg');
var imageResult = await compareImages(src1: /firebase_image_t1/File1, src2: firebase_image_t2 , algorithm: /EuclideanColorDistance( ignoreAlpha: true )/PerceptualHash() );

print('Difference Wala Response A reha ha Aur wo ya ha : ${imageResult * 100}%');
//ya double main value return kar reha ha

// IF KE LOGIC FOR EuclideanColorDistance( ignoreAlpha: true )
//ager difference 0.0% ha to image match kar rahe ha , ager zara sa bhe difference a reha ha to image match nai kar rahe

/*

1)EuclideanColorDistance({bool ignoreAlpha = true}) #

About
Images are resized to the same dimensions (if dimensions don't match) and euclidean difference between [src1] RGB values and [src2] RGB values for each pixel is summed.
Best with images of similar aspect ratios and dimensions
Compare for exactness (if two images are identical)

PerceptualHash(),
If you want to compare two images, construct the hash from each image and count the
number of bit positions that are different. ( This is a Hamming distance. )
A distance of zero indicates that it is likely a very similar picture
(or a variation of the same picture).

A distance of 5 means a few things may

be different, but they are probably
still close enough to be similar.

But a distance of 10 or more? That's probably a very different picture.

/
/

LIABRARY ERRORS

E/flutter ( 3517): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Unsupported operation: The source, String, passed in is unsupported

TYPE IMAGE HA JO A RAHE HA (ERROR DESCRIPTION)
/C:/Users/Developer/AppData/Local/Pub/Cache/hosted/pub.dev/image_compare-1.1.2/lib/src/functions.dart:22:10: Error: A value of type 'Image' can't be assigned to a variable of type 'String'.

IMAGE KE AIK CLASS USE HO RAHE HA , AUR AUS CLASS MAIN DATA int MAIN MAIN PROCESS HO REHA HA
class Image {
/// Width of the image.
final int width;

/// Height of the image.
final int height;
}

*/

}

MY REQUEST

Kindly Fix This Issue as soon as possible because this is good library and have potential to grow please fix this file comparison issue and make proper and complete documentation , on how to compare File to File , File to url and others ,

Kind Regards,
Rehan.

A valid image could not be identified from ...

I'm getting images from gallery. And for compare them I'm getting their bytes or files but it gives the same error in both cases: A valid image could not be identified from Do we have to define images in assets directory?

PNG transparent issue

Hi the library is working fine but I need to use a PNG with transparency and when comparing it always returns 84.766%~ regardless of what I send, is there a setting that I can tweak to fix this issue?
NOTE im using a library to draw on the screen https://pub.dev/packages/painter
It works when I tweak the setting

controller.backgroundColor = Colors.white; and the compare image with white background same PNG format, but when changing to

controller.backgroundColor = Colors.transparent; and using same image but removing the background and leaving it transparent it always return 84.766%~

  PainterController _controller = _newController();

  static PainterController _newController() {
    PainterController controller = new PainterController();
    controller.thickness = 15.0;
    controller.backgroundColor = Colors.transparent;
    return controller;
  }

  void _compare(PictureDetails picture, BuildContext context) async {
    try {
      var render = await picture.toImage();
      var data = await render.toByteData(format: ImageByteFormat.png);
      Uint8List img;
      if (data != null) {
        img = data.buffer.asUint8List();
      } else {
        throw new FlutterError('Flutter failed to convert an Image to bytes!');
      }

       // Recently changed to decodeImage() per stackoverflow suggestion but both work the same and have the same issue when using transparency

      // var image = dart_images.Image.fromBytes(200, 200, img);
      var image = dart_images.decodeImage(img);

      var secondImageData = await rootBundle.load('assets/transparent_img.png');
      var secondImageList = secondImageData.buffer.asUint8List();

      var result = await compareImages(
          src1: image,
          src2: secondImageList,
          algorithm: EuclideanColorDistance());
      print('The difference between images is: ${result * 100}%');
      setState(() {
        _percentage = result * 100;
      });
    } catch (e) {
      print(e);
    }
  }

Issues with images, no difference found

Hello, I have an issue with your package.
I want to compare some images from internet. However, when I compare these images, the result I get is 0.0 but there are differences between the images. The issue is maybe because the images are in black and white.

I tested all your algorithms and I always have a result equals to 0.
I just had a good result when I used the algorithm ChiSquareDistanceHistogram to compare the images "one" and "two" (very low difference because the resultat was 1.3089300910883312e-24) but when I compared the images "two" and "three" the result was 0.

Can you please help me, maybe I don't understand something ?

I'm attaching pictures with which I have this issue.

Regards,
Axel

Images that I use :
One :
one
Two :
two
Three :
three

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.