is there any possibility to read the image from the picture box in vc++ using opencv imread?
am using the following code,
vector< Mat > vImg;
Mat rImg;
vImg.push_back(imread(pictureBox1->Image));
vImg.push_back(imread(pictureBox2->Image));
Stitcher stitcher = Stitcher::createDefault();
stitcher.stitch(vImg, rImg);
but am getting error
What you should do is initialize the Mat object from the PictureBox pixel data directly.
1) Here is an example and short explanation of how to create a Mat object from memory buffer
2) Here you can see how to access the pixel memory of the PictureBox, it is better to use LockBits to obtain the pointer to the memory and pass that in the constructor, but if you are new to all this you can also get it pixel by pixel.
Related
I am using gdcm ImageReader to read multiframe dicom file. It reads multiframe correctly but I am unable to display the multiframe dicom file.
I am using vtkImageViewer to display single frame image,
vtkImageViewer viewer = new vtkImageViewer();
vtkDICOMImageReader reader = new vtkDICOMImageReader();
reader.SetInputfile(..\\inputFile);
viewer.SetInput(reader.GetOutput());
It displays single frame images correctly but does not display multiframe images.
Anybody knows how to display multiframe dicom files???
I would advise you to use vtkImageViewer2 instead of vtkImageViewer in this context. The former has a method, SetSlice, where, according to the documentation:
'Each call to SetSlice() changes the image data (slice) displayed AND changes the depth of the displayed slice in the 3D scene'
Example**:
vtkSmartPointer<vtkImageViewer2> imageViewer = vtkSmartPointer<vtkImageViewer2>::New();
imageViewer->SetSlice(5); //Specify the index/slice in image data
** Assumes you have set the input connection/data, example in c++ language.
Iam completely new to C++ but I am a pro in image processing using MATLAB
Iam looking for a header file (ex: CImg.h )which can read BMP and retrieve length width and 2d array similar to 'imread' function in MATLAB... i am not allowed to use Opencv Opengl
An example would help
TIA
I have a winform application in which there is a pictureBox what displays a pretty big image (2550by4500). This bitmap image is transformed from a byte array using unsafe pointer, like this:
Bitmap img;
unsafe
{
fixed (Byte* intPtr = &outBuffer[0])
img = new Bitmap(_width, _height, _width * 3, System.Drawing.Imaging.PixelFormat.Format24bppRgb, new IntPtr(intPtr));
}
So far, no problems. After displaying the image, I saved the pixel values into a Matlab .mat file using this DLL (http://www.mathworks.com/matlabcentral/fileexchange/16319). Still, no problem with saving.
However, the image in the pictureBox became like a noisy black-white image, the original image was completely lost.
Things I tried:
added the Bitmap in watch window, found out pixel values all changed. Bitmap is corrupted.
do that unsafe transformation again everytime after saving, however, it brings another problem: "AccessViolationException in Drawing.dll".
Something must have to do with the .mat saving part, because if I skip saving, no problem at all. But I do not know how they are related, memory? I tried a smaller size image, no problem. so I'm assuming that "save .mat" process corrupted the Bitmap?
Any idea would be helpful! Thank you
i'm working on a VC++ and OpenCV application, i'm loading images into picturBox and make some OpenCV operations on them, i assign the loaded image into IplImage to make processing on it but then assign the processed image again into the picture box, i write this code to load the image selected from openFileDialog into IplImage ,binarize the image then reassign the binarized image back to the pictureBox
code:
const char* fileName = (const char*)(void*)
Marshal::StringToHGlobalAnsi(openFileDialog1->FileName);
IplImage *img=cvLoadImage(fileName,CV_LOAD_IMAGE_COLOR);
int width=img->width;
int height=img->height;
IplImage *grayScaledImage=cvCreateImage(cvSize(width,height),IPL_DEPTH_8U,1);
cvCvtColor(img,grayScaledImage,CV_RGB2GRAY);
cvThreshold(grayScaledImage,grayScaledImage,128,256,CV_THRESH_BINARY);
this->pictureBox1->Image=(gcnew
System::Drawing::Bitmap(grayScaledImage->width,grayScaledImage->height,grayScaledImage->widthStep,
System::Drawing::Imaging::PixelFormat::Format24bppRgb,(System::IntPtr)grayScaledImage->imageData));
but i doesn't find a format which displays a binary image, any help about that.
Original Image:
Converted image:
You seem to be creating an RGB image (System::Drawing::Imaging::PixelFormat::Format24bppRgb) but copying into it a grayscale, presumably the System::Drawing::Imaging function doesn't do conversion - or isn't doing it properly.
Edit: Some more explanation.
Your greyscale image is stored in memory as one byte for each pixel Y0, Y1, Y2,Y3...... Y639 (we use Y for brightness, and assuming a 640 pixel wide image).
You have told the .net image class that this is Format24bppRgb which would be stored as one red,one green and blue byte per pixel (3bytes = 24bpp). So the class takes your image data and assumes that Y0,Y1,Y2 are the red,green,blue values for he first pixel, Y3,Y4,Y5 for the next and so on.
This is using up 3x as many bytes as your image has, so after 1/3 of the row it starts reading the next row and so on - which gives you the three repeated pictures.
ps. the fact that you have turned it into a binary image just means that the Y values are either 0 or 255 - it doesn't change the data size or shape.
OpenCV provided function to convert Bayer to RGB, but how to use this CV_BayerBG2BGR , and other similar function?
I used code below, but the error appears stated invalid channel number. Since I use RGB image as originalImage, anyway how this function actually works?
void main(){
// Declare and load the image
// Assume we have sample image *.png
IplImage *originalImage = cvLoadImage("bayer-image.jpg",-1);
// The image size is said to be 320X240
IplImage *bayer2RGBImage;
bayer2RGBImage = cvCreateImage(cvSize(100,100),8,3);
cvCvtColor(originalImage,bayer2RGBImage,CV_BayerBG2BGR);
//Save Convertion Image to file.
cvSaveImage("test-result.jpg",bayer2RGBImage);
//Release the memory for the images that were created.
cvReleaseImage(&originalImage);
cvReleaseImage(&bayer2RGBImage);}
Furthermore, I'd like to convert common RGB image to bayer format (let say bilinear) too, whether openCV provide this function as well?
any help would be really appreciated.
Thanks in advance.
Unfortunately OpenCV does not provide BGR to Bayer conversion. Only backward conversion is available.
If you need a conversion to Bayer format then you should implement this conversion yourself or use another library.