python(-209:输入参数的大小不匹配)

时间:2018-11-09 16:12:00

标签: python selenium opencv

我正在尝试 1.获取网址图片屏幕快照image1和 2.稍后与现有图像进行比较。 3.得到两个图像之间的区别 4.计算百分比差异。 我正在使用opencv和selenium和linux操作系统

但是在pycharm中,我可以执行脚本,而在linux中,可以执行此操作。

错误: diff = cv2.subtract(imageA,imageB)

  

cv2.error:OpenCV(3.4.3)   C:\ projects \ opencv-python \ opencv \ modules \ core \ src \ arithm.cpp:659:   错误:(-209:输入参数的大小不匹配)操作为   都不是'array op array'(其中数组具有相同的大小和相同的   通道数),也不能使用“ array op scalar”或“ scalar op array”   函数'cv :: arithm_op'

from pyvirtualdisplay import Display
from selenium import webdriver
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import cv2
import numpy as np
import math

def compare_images(path_one, path_two):
    # imageA= cv2.imread(path_one)
    # imageB= cv2.imread(path_two)

    diff=cv2.subtract(imageA,imageB)
    # cv2.imwrite("diff.jpg",diff)

    # imageC=cv2.imread("C:\Users\divya.nagandla\PycharmProjects\python\supressions1\diff.jpg")

    imgray= cv2.cvtColor(diff,cv2.COLOR_BGR2GRAY)
    cv2.imwrite("check.jpg",imgray)
    ret,thresh = cv2.threshold(imgray,0,255,0)
    cv2.imwrite("check1.jpg",thresh)

    im2, contours, hierarchy = cv2.findContours(imgray, cv2.RETR_TREE, cv2.CHAIN_APPROX_NONE)
    # print contours
    # contours = contours[0]
    for c in contours:
        (x,y,w,h) = cv2.boundingRect(c)
        cv2.rectangle(imageB, (x, y), (x + w, y + h), (0, 255,0), 2)


    cv2.imwrite('Thresh6.png', imageB)


    res = cv2.absdiff(imageA,imageB)
    print res.size

    # res = res.astype(np.uint8)
    # print res1.size
    print np.count_nonzero(res)


    percentage = (float (np.count_nonzero(res) * 100) / res.size)
    # percentage =  (np.count_nonzero(res1)/res1.size)*100

    print percentage


if __name__ == '__main__':

    pic= 'image1.png'
    display = Display(visible=0)
    display.start()
    cap = DesiredCapabilities().FIREFOX
    cap["marionette"] = False
    browser = webdriver.Firefox(capabilities=cap, executable_path='/usr/bin/geckodriver')
    browser = webdriver.Firefox()
    browser.get('http://www.python.org')
    browser.save_screenshot(pic)
    imageA= cv2.imread(pic)
    print pic
    imageB= cv2.imread('home/pfmuser/DIVYA/image.png')
    compare_images(imageA, imageB)
#       browser.close()

0 个答案:

没有答案