[英]How to check if the command cv2.line has changed the image in python opencv
我有一張高分辨率的圖像(黑白),如果我的繪圖命令(例如 cv2.line(...))改變了圖像,我需要該信息。 評論:有可能,像素已經在 cv.line() 的顏色中,那么圖像沒有改變。
目前我正在比較整個圖像,它非常慢(我必須做這個檢查幾次 1000 次。)
img = LARGE IMAGE
#make copy
imgBuffer= img.copy()
#draw on copy
imgBuffer= cv2.line(imgBuffer, point1, point2, colorBlack, 1);
# calc if there is any difference in the images
diffExist = np.any(cv2.absdiff(drawnImageBuffer, contourImage))
有人有更好更有效的想法嗎?
您可以做出的一個明顯的速度改進是僅比較圖像中可能通過繪制一條連接您的兩個給定點的線而改變的部分 - 由您傳遞給 cv2.line( )。
所以運行起來會更快:
img_buffer = orig_img.copy()
x1, y1 = point1
x2, y2 = point2
# make sure x1 and y1 are the lower values
if x2 < x1:
x1, x2 = x2, x1
if y2 < y1:
y1, y2 = y2, y1
cv2.line(img_buffer, point1, point2, colorBlack, 1)
diff_exist = np.any(cv2.absdiff(img_buffer[y1:y2, x1:x2],
orig_img[y1:y2, x1:x2]))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.