Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

A valid image could not be identified from ... #4

Open
burcus opened this issue Oct 15, 2021 · 5 comments
Open

A valid image could not be identified from ... #4

burcus opened this issue Oct 15, 2021 · 5 comments
Assignees
Labels
help wanted Extra attention is needed

Comments

@burcus
Copy link

burcus commented Oct 15, 2021

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?

@nitinramadoss nitinramadoss self-assigned this Oct 16, 2021
@nitinramadoss nitinramadoss added the help wanted Extra attention is needed label Oct 16, 2021
@nitinramadoss
Copy link
Owner

Please share the snippets of code that deal with the images from your gallery. Include how you get the images' bytes and/or file representation. You don't need to have the images in the assets directory.

@burcus
Copy link
Author

burcus commented Oct 18, 2021

I tried both ways (with bytes and files)

  List<Uint8List?> imgBytes = [];
  List<File?> files = [];

  Future<void> analyzeImages() async {

    var assetResults = await listCompare(
      target: imgBytes[0],
      list: imgBytes,
      algorithm: PerceptualHash(),
    );

    assetResults.forEach((e) => print('Difference: ${e * 100}%'));
  }

    Future<void> getBytes() async {
    var result = await PhotoManager.requestPermissionExtend();
    if (result.isAuth) {
      List<AssetPathEntity> list = await PhotoManager.getAssetPathList();
      List<AssetEntity> recents = await list.first.assetList;
      for (var element in recents) {
        if (element.type == AssetType.image) {
          var byteFile = await element.originFile;
          if (byteFile == null) var byteFile = await element.file;
          if (!byteFile!.path.toLowerCase().contains('heic')) {
            files.add(byteFile);
            var bytes = await byteFile.readAsBytesSync();
            imgBytes.add(bytes);
          }
        }
      }
      analyzeImages();
    }
  }

@burcus
Copy link
Author

burcus commented Oct 18, 2021

@nitinramadoss Also when I try to use listCompare there is always "exhausted heap space" error occurs. How many image comparisons do you recommend at once?

@krlaa
Copy link
Collaborator

krlaa commented Oct 25, 2021

Hey, @burcus I am one of the co-developers for the package and I would love to help you out. To replicate this issue can I get some more info? How many images are you trying to compare?

@RehanNG
Copy link

RehanNG commented Mar 2, 2023

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)

  1. 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

4 participants