Ask Your Question

Pzixel's profile - activity

2020-12-02 01:15:36 -0600 received badge  Notable Question (source)
2020-02-03 06:04:37 -0600 received badge  Popular Question (source)
2018-06-08 15:59:53 -0600 commented answer How to search for near identical images?

@berak well, I implemented them all :D so I won't need to choose one.

2018-06-08 03:56:16 -0600 marked best answer How to search for near identical images?

I want to implement an image DB. If i've got it correctly, I need to use BoW and then I would be able to classify a new image if I have seen it before.

But all examples I have seen nefore (e.g. this) have some set of traning images, when training is done then BoW is using to classify the rest.

My situation is different: I have to search through the BoW for an image, and if there is no match then we consider it to be a new image, otherwise we don't add it and say "already exist". Skewed, rescaled and others images should be considered the same, so I used SIFT as a feature detector.

So the problem in a nutshell: At beginning, I have an empty database of images (so I have no data to train on). I have a stream of images. I can calculate features of this image. Then I have check if there is some images which descriptors match descriptors of this image more than some treshold then I say "existing", otherwise I add these descriptors as a new image and return "new image". If I get the same image (or similar image) in future I say "existing".

It requires rebuild BoW with every new image, which seems to be a very complicated solution. All search engines on the internet are doing this so I'm surprised there is almost no information in the web.


Okay, I tried to use PHash to perform a search operation. But it fails to recognize slightly different images. here is a sample code (it's a thin Rust wrapper over C++ interface, so don't be affraid to see an alien language):

pub trait Database {
    fn save_image(&mut self, image: &[u8]);
    fn load_images(&self) -> Vec<Vec<u8>>;
}

pub enum ImageVariant {
    New,
    AlreadyExists
}

pub struct Storage<T: Database> {
    database: T,
    hasher: PHash,
    images: Vec<Mat>
}

impl<T: Database> Storage<T> {
    pub fn new(database: T) -> Self {
        Self {
            database,
            hasher: PHash::new(),
            images: Vec::new()
        }
    }
}

// the main execution happens here
impl<T: Database, D: Clone> Storage<T> {
    pub fn save_image_if_new(&mut self, image: &[u8], filename: &str) -> ImageVariant {
        const DIFF: f64 = 0.5;

        let mat = Mat::image_decode(image, ImageReadMode::Grayscale);
        let mat = self.hasher.compute(&mat);
        let mut last_diff = std::f64::INFINITY;
        for image in self.images.iter() {
            let diff = self.hasher.compare(&mat, &image);
            if diff < last_diff {
                last_diff = diff;
            }
        }
        if last_diff < DIFF {
            return ImageVariant::AlreadyExists;
        }
        self.database.save_image(image);
        self.images.push(mat);
        ImageVariant::New
    }
}

Then I run the test on following images:

  1. image description
  2. image description
  3. image description

So PHash.compare gives distance 28 for images 1 and 2 (should get small distance), while it gives 30 for images 1 and 3 (should get a big distance). So it's practically doesn't allow to know if I already say this image before.

The entire code is available here and here

Test code:

#[test]
fn it_works() {
    let lenna = fs::read(get_asset_path("lenna.png")).unwrap();
    let lenna_demotivator = fs::read(get_asset_path("lenna_demotivator.png")).unwrap();
    let ...
(more)
2018-06-08 03:55:03 -0600 commented answer How to search for near identical images?

Hmm, I didn't notice that colormoments gave very good results. Going to try it. Thank you.

2018-06-08 03:48:16 -0600 commented answer How to search for near identical images?

@berak. I did it once, but I've got an error that Mat have different sizes. So I learned documentation and I actually co

2018-06-08 03:46:00 -0600 commented answer How to search for near identical images?

@berak. I did it once, but I've got an error that Mat have different sizes. So I learned documentation and I actually co

2018-06-08 03:45:19 -0600 commented answer How to search for near identical images?

@berak. I did it once, but I've got an error that Mat have different sizes. So I learned documentation and I actually co

2018-06-08 03:44:14 -0600 edited question How to search for near identical images?

How to train BoW incrementaly? I want to implement an image DB. If i've got it correctly, I need to use BoW and then I w

2018-06-08 03:43:56 -0600 edited question How to search for near identical images?

How to train BoW incrementaly? I want to implement an image DB. If i've got it correctly, I need to use BoW and then I w

2018-06-08 03:43:00 -0600 commented answer How to search for near identical images?

@berak. I did it once, but I've got an error that Mat have different sizes. So I learned documentation and I actually co

2018-06-07 16:40:19 -0600 edited question How to search for near identical images?

How to train BoW incrementaly? I want to implement an image DB. If i've got it correctly, I need to use BoW and then I w

2018-06-07 16:37:52 -0600 edited question How to search for near identical images?

How to train BoW incrementaly? I want to implement an image DB. If i've got it correctly, I need to use BoW and then I w

2018-06-07 16:37:05 -0600 edited question How to search for near identical images?

How to train BoW incrementaly? I want to implement an image DB. If i've got it correctly, I need to use BoW and then I w

2018-06-07 16:26:32 -0600 edited question How to search for near identical images?

How to train BoW incrementaly? I want to implement an image DB. If i've got it correctly, I need to use BoW and then I w

2018-06-07 16:25:52 -0600 commented answer How to search for near identical images?

@berak please, see edit.

2018-06-07 16:25:43 -0600 edited question How to search for near identical images?

How to train BoW incrementaly? I want to implement an image DB. If i've got it correctly, I need to use BoW and then I w

2018-06-06 17:43:21 -0600 commented answer How to search for near identical images?

Well, I face an issue OpenCV(3.4.1) Error: Assertion failed (_src1.sameSize(_src2) && _src1.type() == _src2.type

2018-06-06 16:31:36 -0600 commented answer How to search for near identical images?

Well, I face an issue OpenCV(3.4.1) Error: Assertion failed (_src1.sameSize(_src2) && _src1.type() == _src2.type

2018-05-25 05:01:58 -0600 commented answer How to search for near identical images?

I upvote it for now, I'l accept it when I try it (if you don't mind).

2018-05-25 04:45:47 -0600 commented question How to search for near identical images?

That's what I call XY :) . Please, write it as an answer, noone would like to read all the comments, but terse and accur

2018-05-25 04:31:24 -0600 commented question How to search for near identical images?

I have a chat. I have a webhook that triggers when someone adds an image to the chat. I have to say if this image was pr

2018-05-25 03:53:24 -0600 commented question How to search for near identical images?

Well, maybe BoW is a no way here and it's an XY problem. This is why I add so much context, to make a decision wheighted

2018-05-25 03:46:52 -0600 edited question How to search for near identical images?

How to train BoW incrementaly? I want to implement an image DB. If i've got it correctly, I need to use BoW and then I w

2018-05-25 03:46:29 -0600 commented question How to search for near identical images?

@berak I have rewritten my question more clearly, please, feel free to give a new feedback if I'm doing something wrong.

2018-05-25 03:45:51 -0600 edited question How to search for near identical images?

How to train BoW incrementaly? I want to implement an image DB. If i've got it correctly, I need to use BoW and then I w

2018-05-25 03:45:25 -0600 edited question How to search for near identical images?

How to train BoW incrementaly? I want to implement an image DB. If i've got it correctly, I need to use BoW and then I w

2018-05-25 03:45:00 -0600 edited question How to search for near identical images?

How to train BoW incrementaly? I want to implement an image DB. If i've got it correctly, I need to use BoW and then I w

2018-05-25 03:44:48 -0600 edited question How to search for near identical images?

How to train BoW incrementaly? I want to implement an image DB. If i've got it correctly, I need to use BoW and then I w

2018-05-25 03:43:55 -0600 commented question How to search for near identical images?

@berak I have rewritten my question more clearly, please, feel free to give a new feedback if I'm doing something wrong.

2018-05-25 03:42:00 -0600 edited question How to search for near identical images?

How to train BoW incrementaly? I want to implement an image DB. If i've got it correctly, I need to use BoW and then I w

2018-05-25 03:40:50 -0600 edited question How to search for near identical images?

How to train BoW incrementaly? I want to implement an image DB. If i've got it correctly, I need to use BoW and then I w

2018-05-25 03:33:47 -0600 edited question How to search for near identical images?

How to build a fuzzy image database on top of OpenCV? I'm learning this topic for last 6 months but still unable to do i

2018-05-25 03:29:39 -0600 commented question How to search for near identical images?

@berak okay, i removed some consideration, if you like to. My question is straight: how can a DB being implemented? All

2018-05-25 03:29:26 -0600 commented question How to search for near identical images?

@berak okay, i removed some consideration, if you like so. My question is strait: how can a DB being implemented? All ex

2018-05-25 03:29:17 -0600 commented question How to search for near identical images?

@berak okay, i removed some consideration, if you like so. My question is strait: how can a DB being implemented? All ex

2018-05-25 03:28:46 -0600 commented question How to search for near identical images?

@berak okay, i removed some consideration, if you like to. My question is strait: how can a DB being implemented? All ex

2018-05-25 03:28:22 -0600 commented question How to search for near identical images?

@berak okay, i removed some consideration, if you like to. My question is strait: how can a DB being implemented? All ex

2018-05-25 03:26:19 -0600 edited question How to search for near identical images?

How to build a fuzzy image database on top of OpenCV? I'm learning this topic for last 6 months but still unable to do i

2018-05-24 18:18:42 -0600 asked a question How to search for near identical images?

How to build a fuzzy image database on top of OpenCV? I'm learning this topic for last 6 months but still unable to do i

2018-03-06 00:25:37 -0600 marked best answer Does OpenCV runs on platforms with different int size?

I'm writing a library on top of the OpenCV and I have a question about crossplatformability.

So my question is: does OpenCV runs if int size is other than 32 bits, but 16, 64 or 128? Because if yes, I'd like to support those platforms, otherwise it would simplify my high level interfaces.

Up

2018-03-05 14:33:42 -0600 commented answer Does OpenCV runs on platforms with different int size?

Hmm, I see a comment that says that int should be 4 bytes but I don't see any macro or something enforcing this rule (e.

2018-03-05 12:36:42 -0600 edited question Does OpenCV runs on platforms with different int size?

Does OpenCV runs on platforms with different int size? I'm writing a library on top of the OpenCV and I have a question

2018-03-05 11:34:23 -0600 received badge  Student (source)
2018-03-05 11:02:11 -0600 commented question Does OpenCV runs on platforms with different int size?

@berak can I ask you to visit this question? It seens that it isn't really get enough attention. :(

2018-03-01 03:43:31 -0600 marked best answer Is C API alive or not

I want to write a wrapper for OpenCV using different language. For obsious reasons I can only use C API. And I have two alternatives: write my own wrappers over C++ code and expose it OR I can take existing C API, but the drawback of this approach is my fear that C bindings may be abandoned.

I'm starting a new shiny project, but I don't want to write extra C code when I can reuse existing one. Or I can't? Because as I see multiple functions are missing, even very basic ones, like mat::zeroes or mat::eye.

2018-02-28 13:40:04 -0600 commented question Is C API alive or not

I feel that you are right. However, I don't believe I can handle it, because I'm not familiar with python at all, and my