久久久久久久av_日韩在线中文_看一级毛片视频_日本精品二区_成人深夜福利视频_武道仙尊动漫在线观看

使用 OpenCV 組合兩個圖像

Combining Two Images with OpenCV(使用 OpenCV 組合兩個圖像)
本文介紹了使用 OpenCV 組合兩個圖像的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我正在嘗試使用 OpenCV 2.1 將兩個圖像合二為一,兩個圖像彼此相鄰放置.在 Python 中,我正在做:

I'm trying to use OpenCV 2.1 to combine two images into one, with the two images placed adjacent to each other. In Python, I'm doing:

import numpy as np, cv

img1 = cv.LoadImage(fn1, 0)
img2 = cv.LoadImage(fn2, 0)

h1, w1 = img1.height,img1.width
h2, w2 = img2.height,img2.width

# Create an array big enough to hold both images next to each other.
vis = np.zeros((max(h1, h2), w1+w2), np.float32)

mat1 = cv.CreateMat(img1.height,img1.width, cv.CV_32FC1)
cv.Convert( img1, mat1 )

mat2 = cv.CreateMat(img2.height, img2.width, cv.CV_32FC1)
cv.Convert( img2, mat2 )

# Copy both images into the composite image.
vis[:h1, :w1] = mat1
vis[:h2, w1:w1+w2] = mat2

h,w = vis.shape
vis2 = cv.CreateMat(h, w, cv.CV_32FC3)
vis0 = cv.fromarray(vis)
cv.CvtColor(vis0, vis2, cv.CV_GRAY2BGR)
cv.ShowImage('test', vis2)
cv.WaitKey()

兩個輸入圖像是:

https://code.ros.org/trac/opencv/browser/trunk/opencv/samples/c/box.png?rev=2270

https://code.ros.org/trac/opencv/browser/trunk/opencv/samples/c/box_in_scene.png?rev=2270

生成的圖像是:

可能很難與網站的其他部分區分開來,但大部分圖像都是白色的,對應于單個圖像應該在的位置.黑色區域是沒有寫入圖像數據的地方.

It may be hard to distinguish from the rest of the site, but most of the image is white, corresponding to where the individual images should be. The black area is where no image data was written.

為什么我的所有圖像數據都被轉換為白色?

Why is all my image data being converted to white?

推薦答案

對于你的圖片恰好大小相同的情況(這是顯示圖片處理結果的常見情況),你可以使用 numpy 的 concatenate 來簡化你的代碼.

For cases where your images happen to be the same size (which is a common case for displaying image processing results), you can use numpy's concatenate to simplify your code.

垂直堆疊(img1 over img2):

To stack vertically (img1 over img2):

vis = np.concatenate((img1, img2), axis=0)

水平堆疊(img1在img2的左邊):

To stack horizontally (img1 to the left of img2):

vis = np.concatenate((img1, img2), axis=1)

驗證:

import cv2
import numpy as np
img1 = cv2.imread('img1.png')
img2 = cv2.imread('img2.png')
vis = np.concatenate((img1, img2), axis=1)
cv2.imwrite('out.png', vis)

out.png 圖像將在左側包含 img1,在右側包含 img2.

The out.png image will contain img1 on the left and img2 on the right.

這篇關于使用 OpenCV 組合兩個圖像的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

How to draw a rectangle around a region of interest in python(如何在python中的感興趣區域周圍繪制一個矩形)
How can I detect and track people using OpenCV?(如何使用 OpenCV 檢測和跟蹤人員?)
How to apply threshold within multiple rectangular bounding boxes in an image?(如何在圖像的多個矩形邊界框中應用閾值?)
How can I download a specific part of Coco Dataset?(如何下載 Coco Dataset 的特定部分?)
Detect image orientation angle based on text direction(根據文本方向檢測圖像方向角度)
Detect centre and angle of rectangles in an image using Opencv(使用 Opencv 檢測圖像中矩形的中心和角度)
主站蜘蛛池模板: 视频一区二区在线观看 | 日本网站在线看 | 一区二区三区中文字幕 | 中文字幕视频在线观看免费 | 看黄在线| 天天草夜夜骑 | 国产精品视频偷伦精品视频 | www.国产一区| 视频一区中文字幕 | 成人免费视频 | www.97国产| 紧缚调教一区二区三区视频 | 欧美日韩国产一区二区三区 | 国产中文字幕在线 | 91在线视频免费观看 | 欧美亚洲视频 | 亚洲精品91 | 91传媒在线观看 | 欧美精品在线播放 | 男人的天堂在线视频 | 国产性生活一级片 | 欧美性视频在线播放 | 久久精品国产一区二区电影 | 中文二区 | eeuss国产一区二区三区四区 | 国产在线精品一区 | 综合色在线 | 日韩欧美亚洲 | 91精品无人区卡一卡二卡三 | 99热精品在线观看 | 九九热在线免费观看 | 日韩一区二区三区在线观看 | 99视频网| 亚洲精品天堂 | 国产一区二区三区欧美 | www.国产精 | 国产乱码精品1区2区3区 | 欧美性网 | 男人天堂网站 | 国产视频精品在线观看 | 成人做爰www免费看 午夜精品久久久久久久久久久久 |