私はpythonでraspberry piにコードを書き、平均二乗誤差を使って二つの画像を比較しています。このプロジェクトは個人的な家庭のセキュリティです。openCVで画像の比較をより粗くするには
私の主な目標は、私がpiカメラからキャプチャした画像(何かが現在の画像に追加されたものか、画像から削除されたもの)の間の変化を検出することです。それは、私が欲しくない背景の照明の変化の影響を受けます。
私の前に2つのオプションがあり、現在のロジックを掻き集めて新しいロジックを開始するか、またはこれらのノイズを考慮して現在のロジックを改善しています。私は自分のロジックを改善する方法を模索していますが、私はそれについてどうやっていくべきかについての指針を求めました。
私の最大の恐怖であることは、私が死んだ馬を蹴って時間を無駄にしていたり、エッジ検出
import numpy as np
import cv2
import os
from threading import Thread
######Function Definition########################################
def mse(imageA, imageB):
# the 'Mean Squared Error' between the two images is the
# sum of the squared difference between the two images;
# NOTE: the two images must have the same dimension
err = np.sum((imageA.astype("int") - imageB.astype("int")) ** 2)
err /= int(imageA.shape[0] * imageA.shape[1])
# return the MSE, the lower the error, the more "similar"
# the two images are
return err
def compare_images(imageA, imageB):
# compute the mean squared error
m = mse(imageA, imageB)
print(m)
def capture_image():
##shell command to click photos
os.system(image_args)
##original image Path variable
original_image_path= "/home/pi/Downloads/python-compare-two-images/originalimage.png"
##original_image_args is a shell command to click photos
original_image_args="raspistill -o "+original_image_path+" -w 320 -h 240 -q 50 -t 500"
os.system(original_image_args)
##read the greyscale of the image in to the variable original_image
original_image=cv2.imread(original_image_path, 0)
##Three images
image_args="raspistill -o /home/pi/Downloads/python-compare-two-images/Test_Images/image.png -w 320 -h 240 -q 50 --nopreview -t 10 --exposure sports"
image_path="/home/pi/Downloads/python-compare-two-images/Test_Images/"
image1_name="image.png"
#created a new thread to take pictures
My_Thread=Thread(target=capture_image)
#Thread started
My_Thread.start()
flag = 0
while(True):
if(My_Thread.isAlive()==True):
flag=0
else:
flag=1
if(flag==1):
flag=0
image1 = cv2.imread((image_path+image1_name), 0)
My_Thread=Thread(target=capture_image)
My_Thread.start()
compare_images(original_image, image1)
この場合のゲインは、compare_image()関数の 'm'になります –
@ShravanSingh:ではありませんすべて。平均の比率になるでしょう。 –