cv2_imshow((predict[0].masks.masks[0].numpy() * 255).astype("uint8"))
In this script I can to read one image but how can reed multiple images in predict[]?
is predict a list of objects? if so, does this help?
import cv2
# Loop over all the masks in predict
for mask in predict:
# Display the mask for the first object in the list
cv2.imshow('Mask', (mask.masks.masks[0].numpy() * 255).astype("uint8"))
cv2.waitKey(0)
# Close all windows when done
cv2.destroyAllWindows()
Related
I need to compare two images and get RGB differences using one of that as reference:
I'm using this code,
from PIL import Image, ImageChops
img1 = Image.open("sagitale1pos.png")
img2 = Image.open("sagitale1pre.png")
diff = ImageChops.difference(img1, img2)
if diff.getbbox():
diff.show()
but it returns all differences between images, and I want to see only the changes in image 2.
Thanks for help
I've got two images, the first one contain multiple items, which shows true colors. Then when I removed most of the item, then the webcam tried to auto-balance the image and yielded really false color.
Is there a way (in code) to apply the color profile of the first (true-color) image to the second image?
(or point me to some keywords, I'm new to the field, thanks)
Attached them here for easy comparison
True color
Falsely-adjusted color
I used Logitech webcam, which I can't figure out how to turn off auto-balance in code (in Linux).
I use this method and it works very well:
#pip install color_transfer
from color_transfer import color_transfer
# Load the two images
img1 = cv2.imread('image12.png')
img2 = cv2.imread('image1.png')
# Apply the color transfer
img2_transferred = color_transfer(img1, img2)
cv2.imshow("image", img2_transferred)
if cv2.waitKey(0) == chr("q"):
exit(0)
I have two images
Image 1:
Image 2:
I tried various approaches but I got some errors. I also tried this approach. So, can we stitch these two images? If so, how can I do this in Python3?
What would be your error? I tested using your images and it indeed produces error because OpenCV Stitcher cannot find the overlapping features between the two images. You can try to other images with at least 25% overlapping between the two images and use the simpler code for image stitching below.
import cv2
img1 = cv2.imread("image1.jpg")
img2 = cv2.imread("image2.jpg")
tupleImages=(img1,img2)
stitcher = cv2.createStitcher(True)
result = stitcher.stitch(tupleImages)
cv2.imshow('result',result[1])
k = cv2.waitKey(0) & 0xff # press ESC to exit
if k == 27:
cv2.destroyAllWindows()
Try using the images below and the result would be
So what I have is two images extracted from video of cold-drink cans. In the first image all the 5 cans are present:
And in the second image one is missing:
So what I want is to find out which of the can was picked out of 5. I tried applying the cv2.subtract but it doesnt seem to give me the desired result.
How can I achieve what I am trying to achieve using opencv python? I'm using Python 3.5 and opencv 3.1. Any help is appreciated. This the code:
import numpy as np
import cv2
import os
import sys
img1=cv2.imread("IMG_3.jpg")
img2=cv2.imread("IMG_4.jpg")
r_img=cv2.subtract(img1, img2)
cv2.namedWindow("output", cv2.WINDOW_NORMAL)
cv2.resizeWindow("output", 400, 300)
cv2.imshow("output", r_img)
cv2.waitKey(0)
cv2.destroyAllWindows()
And this is the output image
I want to superimpose a given set of images of the same size (the AT&T facial images database). I have written the code to do so, which works as follows:
I have assigned the location of the images (for starting I am considering only 4 images).
imstack is used to read one image (as a base image) over which the layover (superimposition) will take place.
A for loop is run that goes through all the images and adds them to the base image (imstack). This adding is done by using the addWeighted() function with the parameters as the current image (im) and the base image (imstack) with the alpha values as 0.5 respectively.
After the loop has run till its completion (all the images are superimposed on the base image) I tried to print the updated imstack as 'compiledimg' by using the imshow().
Further I added the option to save the 'compiledimg' file by pressing 's'.
To fix the error what I have tried is to resize the image after every iteration so that the addWeighted() function receives the images with the same dimensions. First imsize (before entering the for loop) is resized as to set a firm base to the first image with the required size that I have taken as (97(rows),113(columns)).
I don't understand why the addWeighted function is not working because I am using the resize funtion to make sure that the size is kept the same after each iteration. Plus, if also tried to superimpose just two of the images and it worked perfectly fine however it does not work when I try to use the addWeighted() on the third image.
Say I used addWeighted on two images img1 and img2 and stored in img3. Now when I tried to use the addWeighted() on img3 and img4 I am getting the error. Even when I have used the resize function on img3.
Note: Initial size of the images is (97 (rows),113 (columns)) hence I am trying to keep the same image size.
import cv2
import numpy as np
import os
fnames =['~/Downloads/1.pgm','~/Downloads/2.pgm','~/Downloads/3.pgm']
imstack=cv2.imread('~/Downloads/4.pgm')
for path in fnames:
im=cv2.imread(os.path.expanduser(path))
im=cv2.resize(im,(97,113))
imstack=cv2.addWeighted(imstack,0.5,im,0.5,0)
imstack=cv2.resize(imstack,(97,113))
cv2.imshow('compiledimg',imstack)
k = cv2.waitKey(0) & 0xFF
if k == 27:
cv2.destroyAllWindows()
elif k == ord('s'):
cv2.imwrite('compiledimg.pgm',imstack)
cv2.destroyAllWindows()