I plan to do a stereo image from the tutorial here, but the compiler reports errors with cv2.createStereoBM, I found out it was the problem of OpenCV version.
I followed this to change cv2.createStereoBM into cv2.StereoBM. It works well, but the following code:
disparity = stereo.compute(frame0,frame1)
shows error:
Both input images must have CV_8UC1 in function cv::findStereoCorrespondenceBM
Can anyone help me with this?
The environment is Python 2.7, OpenCV 2.4.11.
My code is:
cap0 = cv2.VideoCapture(0)
cap1 = cv2.VideoCapture(1)
while (cap0.isOpened() and cap1.isOpened()):
ret0, frame0 = cap0.read()
frame0_new=cv2.cvtColor(frame0, cv2.COLOR_BGR2GRAY)
ret1, frame1 = cap1.read()
frame1_new=cv2.cvtColor(frame1, cv2.COLOR_BGR2GRAY)
stereo = cv2.StereoBM(cv2.STEREO_BM_BASIC_PRESET,ndisparities=16, SADWindowSize=15)
disparity = stereo.compute(frame0,frame1)
You should use your frames converted to single channel, i.e. of type CV_8UC1:
disparity = stereo.compute(frame0_new, frame1_new)
Related
Using NetVips,
using var per = Image.Perlin(800,800,33,true,3434);
using var per2 = Image.Perlin(800,800,13,true,3435);
using var per3 = Image.Perlin(800,800,13,true,3435);
using var comp = per.Composite(new []{per2, per3},new []{Enums.BlendMode.ColourBurn, Enums.BlendMode.Lighten},compositingSpace:Enums.Interpretation.Rgb);
yeilds
Exception has occurred: CLR/NetVips.VipsException
An unhandled exception of type 'NetVips.VipsException' occurred in NetVips.dll: 'unable to call composite
vips_colourspace: no known route from 'b-w' to 'rgb''
not sure how to get image from perlin, b-w to rgb basically.
Try using sRGB instead of RGB, you should get an image.
Though it'll be black and white since you are compositing black and white images. Did you want to join the three perlin images together as RGB? You need bandjoin, eg. in Python:
#!/usr/bin/python3
import pyvips
per1 = pyvips.Image.perlin(800, 800, cell_size=33, uchar=True, seed=3434)
per2 = pyvips.Image.perlin(800, 800, cell_size=13, uchar=True, seed=3435)
per3 = pyvips.Image.perlin(800, 800, cell_size=13, uchar=True, seed=3435)
# join the three one-band images up as a three-band image, tag as sRGB
image = per1.bandjoin([per2, per3]).copy(interpretation="srgb")
image.write_to_file("x.png")
To make:
I have one transparent SVG image, I am trying to generate the thumbnail of that image. It generates a thumbnail of the image properly, but it removes the transparency of the image and adds a black background to the image. I want to generate thumbnail without losing the transparency of the image.
Note - The same problem with jpg and jpeg images also, but I added white background to the image in svg case it's not make the transparent background
I am using PHP vips library.
Here is my code for that
$im = Vips\Image::thumbnail($filename, 180, ['height' => 225, 'size' => 'both']);
$alpha = $im->hasAlpha();
if($alpha) {
$im = $im->flatten(['background' => [255, 255, 255]]);
}
Just write to a format that supports transparency, like PNG.
For example:
$im = Vips\Image::thumbnail("x.svg", 180, ['height' => 225, 'size' => 'both']);
$im->WriteToFile("x.png");
WEBP, GIF, HEIC, AVIF, TIFF etc. also support transparency. JPEG does not.
Am trying to create transparent mat but am getting black background image in return so any idea how to do it as i have to overlay this image with some content on camera video feed.
code i tried.
cv::Mat comp = cv::Mat::zeros( currentImage.size(), CV_8UC4 );
comp.setTo(cv::Scalar(0,0,0,0));
imshow( "transparent", comp ); // show black background image.
thanks to #HansHire and #Scheff we find out that problem is in cv::imshow() it not render transparency so to check Mat for transparency it need to dumped to disk to be checked using system image viewer which render transparency very well
cv::Mat comp = cv::Mat::zeros( currentImage.size(), CV_8UC4 );
comp.setTo(cv::Scalar(0,0,0,0));
// imshow( "transparent", comp ); // show black background image because it cant render transparency .
imwrite( "C:/opencv_dump.png", comp ); // transparent upon opening , thumbnail may look black.
I am trying to display an image (with an alpha value) in a window (of size 200X200). The image is loaded into an OpenCV Mat datastructure.
The image I am loading, looks like this:
The image i see when displayed, looks like this:
The code I am using to load the Bitmap is as follows:
NSBitmapImageRep* imageRep = [[[NSBitmapImageRep alloc] initWithBitmapDataPlanes:nil
pixelsWide:200
pixelsHigh:200
bitsPerSample:8
samplesPerPixel:4
hasAlpha:YES
isPlanar:NO
colorSpaceName:NSDeviceRGBColorSpace
bytesPerRow:(200*4)
bitsPerPixel:32] autorelease];
memcpy(imageRep.bitmapData,paintBuffer.data,160000);
NSSize imageSize = NSMakeSize(200,200);
NSImage* myImage = [[[NSImage alloc] initWithSize: imageSize] autorelease];
[myImage addRepresentation:imageRep];
g_imageView setImage:myImage];
Update:
I was initially reading BGRA instead of the expected RGBA. On changing that, I just get a red version of image above, like this:
I've been scratching my head for a few days on how to complete the task of making the edges rounded on an image taken from picamera using python-wand. I have it setup now to where it grabs the image and composites it over the banner/background image with the following:
img = Image(filename=Picture)
img.resize(1200, 800)
bimg = Image(filename=Background)
bimg.composite(img, left=300, top=200)
bimg.save(filename=BPicture)
Any help is appreciated!
You can use wand.drawing.Drawing.rectangle to generate rounded corners, and overlay it with composite channels.
from wand.image import Image
from wand.color import Color
from wand.drawing import Drawing
with Image(filename='rose:') as img:
img.resize(240, 160)
with Image(width=img.width,
height=img.height,
background=Color("white")) as mask:
with Drawing() as ctx:
ctx.fill_color = Color("black")
ctx.rectangle(left=0,
top=0,
width=mask.width,
height=mask.height,
radius=mask.width*0.1) # 10% rounding?
ctx(mask)
img.composite_channel('all_channels', mask, 'screen')
img.save(filename='/tmp/out.png')
Now if I understand your question, you can apply the same technique, but composite Picture in the drawing context.
with Image(filename='rose:') as img:
img.resize(240, 160)
with Image(img) as nimg:
nimg.negate() # For fun, let's negate the image for the background
with Drawing() as ctx:
ctx.fill_color = Color("black")
ctx.rectangle(left=0,
top=0,
width=nimg.width,
height=nimg.height,
radius=nimg.width*0.3) # 30% rounding?
ctx.composite('screen', 0, 0, nimg.width, nimg.height, img)
ctx(nimg)
nimg.save(filename='/tmp/out2.png')