Ask Your Question
0

Detecting changes of image

asked 2020-02-17 01:37:53 -0600

I have a project involving batteries(18650 battery). I have a pack of them in a certain order(some are upwards showing the positive side and some are showing the negative). What i'm trying to do is take a pack that is in the correct form as a reference image (an image that is the correct order of the batteries) and capture another image(for example with the same pack with one battery that is incorrect in all the pack). How can i detect a difference between the referenced image to the current image and highlight the problematic battery.(to make it more clear, the positive has a different "look" than the negative). My goal is to detect changes between the original image to the newly taken image.

edit retag flag offensive close merge delete

Comments

1

please add example images

(if you can fix the camera and the battery position, maybe a simple absdiff() will already do ...)

berak gravatar imageberak ( 2020-02-17 03:35:42 -0600 )edit
1

C:\fakepath\image 1.jpgC:\fakepath\image 2.jpg for example image 1 is the correct form of the pack and image 2 is an incorrect pack. and yes the image will be taken in a standstill position with same light exposure and angle with same pack width height and position.

a.s7721 gravatar imagea.s7721 ( 2020-02-17 04:37:22 -0600 )edit

ah, but as it looks, the battery can have any 90° rotation, right ?

berak gravatar imageberak ( 2020-02-17 05:54:37 -0600 )edit
1

The pack stays the same. In this case I changed the sleeves. but my goal is, same pack. same positioning of the sleeves, and just detect any battery that is in the wrong position. so no 90 degree rotation

a.s7721 gravatar imagea.s7721 ( 2020-02-17 06:13:17 -0600 )edit

I am looking at first image. The battery upside up(positive) contained 2 circulars while battery upside-down(negative) contained merely one circular. You need to do 2 things findcontours and inrange colors. I noticed some some battery have different colours.

supra56 gravatar imagesupra56 ( 2020-02-18 03:39:13 -0600 )edit

2 answers

Sort by » oldest newest most voted
0

answered 2020-02-20 04:44:01 -0600

berak gravatar image

updated 2020-02-20 04:45:20 -0600

maybe simple template matching already does the trick.

we can also check "per battery" in the pack:

image description

float sim(const Mat &q, const Mat &t) {
    Mat res;
    matchTemplate(q,t,res,TM_CCOEFF);
    double m; Point p;
    minMaxLoc(res,0,&m,0,&p);
    // p should be in top-left half of our quadrant
    cout << p << " " << (Rect(0,0,q.cols/2,q.rows/2).contains(p)) << " " << m << endl;
    return m;
}
int main()
{
    Mat input = imread("battery2.jpg", 0);
    Mat templ = imread("battery_t2.jpg", 0);

    // slice image into 4 overlapping regions:
    Rect tl(0,0,input.cols/1.9,input.rows/1.9);
    Rect tr(input.cols/2.3,0,input.cols/1.9,input.rows/1.9);
    Rect bl(0,input.rows/2.3,input.cols/1.9,input.rows/1.9);
    Rect br(input.cols/2.3,input.rows/2.3,input.cols/1.9,input.rows/1.9);
    // check similarity per region:
    float r1 = sim(input(tl),templ);
    float r2 = sim(input(tr),templ);
    float r3 = sim(input(bl),templ);
    float r4 = sim(input(br),templ);
    return 0;
}

for the 2nd (wrong) image:

[33, 360] 0 5.76699e+07
[169, 220] 1 7.66588e+07
[171, 186] 1 1.70977e+08
[25, 324] 0 3.40818e+07
edit flag offensive delete link more
0

answered 2020-02-17 03:04:15 -0600

holger gravatar image

updated 2020-02-17 03:04:49 -0600

One solution to your problem could be to use a image classifier to classify batteries as "correct/uncorrect" packed. This topic is a bit too broad to discuss it here i think - but the good thing is - there are tutorials out there - what is an image classifier and how to train one.

The evaluation can be done in opencv - the training not. But i don't want to confuse you too much, read about image classification first.

edit flag offensive delete link more

Question Tools

1 follower

Stats

Asked: 2020-02-17 01:37:53 -0600

Seen: 805 times

Last updated: Feb 20 '20