2012-06-17 18 views

Respuesta

7

sí lo es, aquí es un ejemplo, expaination en los comentarios:

enter image description here

import cv 
#open color and b/w images 
im = cv.LoadImageM('1_tree_small.jpg') 
im2 = cv.LoadImageM('1_tree_small.jpg',cv.CV_LOAD_IMAGE_GRAYSCALE) 
#set up our output and b/w in rgb space arrays: 
bw = cv.CreateImage((im.width,im.height), cv.IPL_DEPTH_8U, 3) 
new = cv.CreateImage((im.width*2,im.height), cv.IPL_DEPTH_8U, 3) 
#create a b/w image in rgb space 
cv.Merge(im2, im2, im2, None, bw) 
#set up and add the color image to the left half of our output image 
cv.SetImageROI(new, (0,0,im.width,im.height)) 
cv.Add(new, im, new) 
#set up and add the b/w image to the right half of output image 
cv.SetImageROI(new, (im.width,0,im.width,im.height)) 
cv.Add(new, bw, new) 
cv.ResetImageROI(new) 
cv.ShowImage('double', new) 
cv.SaveImage('double.jpg', new) 
cv.WaitKey(0) 

Su en Python, pero fácil de convertir a cualquier .. respuesta

+0

gracias Fraxel mucho. Esto es lo que estoy buscando. Gracias otra véz. – mvr950

32

de Fraxel ha resuelto el problema con la vieja interfaz cv. Me gustaría mostrarlo usando la interfaz cv2, solo para entender cómo es fácil en el nuevo módulo cv2. (Puede ser que sería útil para futuros visitantes). A continuación se muestra el código:

import cv2 
import numpy as np 

im = cv2.imread('kick.jpg') 
img = cv2.imread('kick.jpg',0) 

# Convert grayscale image to 3-channel image,so that they can be stacked together  
imgc = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR) 
both = np.hstack((im,imgc)) 

cv2.imshow('imgc',both) 
cv2.waitKey(0) 
cv2.destroyAllWindows() 

Y a continuación es la salida que tengo:

enter image description here

+0

Gracias por la nueva versión. – mvr950

+0

@ abid-rahman-k ¿se puede hacer lo mismo con los videos? sin convertir uno en escala de grises? –

1

pequeña mejora al código con la escritura moderna

concatenar

en lugar de

hstack

que se suspendió (pila también se puede utilizar)

import cv2 
import numpy as np 

im = cv2.imread('kick.jpg') 
img = cv2.imread('kick.jpg',0) 

# Convert grayscale image to 3-channel image,so that they can be stacked together  
imgc = cv2.cvtColor(img,cv2.COLOR_GRAY2BGR) 
both = np.concatenate((im,imgc), axis=1) #1 : horz, 0 : Vert. 

cv2.imshow('imgc',both) 
cv2.waitKey(0) 
cv2.destroyAllWindows() 
Cuestiones relacionadas