È possibile avere immagini in bianco e nero ea colori sulla stessa finestra usando il libraray opencv? Come posso avere entrambe queste immagini sulla stessa finestra?È possibile avere immagini in bianco e nero ea colori sulla stessa finestra usando opencv?
risposta
Sì, lo è, ecco un esempio, expaination nei commenti:
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)
sua in pitone, ma facile da convertire in qualsiasi .. risposta
di Fraxel ha risolto il problema con la vecchia interfaccia cv. Mi piacerebbe mostrarlo usando l'interfaccia cv2, solo per capire come questo sia facile nel nuovo modulo cv2. (Potrebbe essere utile per i futuri visitatori). Di seguito è riportato il codice:
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()
E di seguito è l'output che ho ottenuto:
Grazie per la nuova versione. – mvr950
@ abid-rahman-k può fare lo stesso con i video? senza trasformare uno in scala di grigi? –
piccolo miglioramento per il codice con la scrittura moderna
concatenate
invece di
hstack
che viene interrotto (stack può essere utilizzato anche)
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()
Grazie Fraxel sacco. Questo è quello che sto cercando. Grazie ancora. – mvr950