I am trying to access pixel data from video from webcam in JavaCV.
This is the code i used to display video in screen.
CvCapture capture =opencv_highgui.cvCreateCameraCapture(0);
opencv_highgui.cvSetCaptureProperty(capture, opencv_highgui.CV_CAP_PROP_FRAME_HEIGHT, 720);
opencv_highgui.cvSetCaptureProperty(capture, opencv_highgui.CV_CAP_PROP_FRAME_WIDTH, 720);
IplImage grabbedimage = opencv_highgui.cvQueryFrame(capture);
CanvasFrame frame = new CanvasFrame("Camera");
while(frame.isVisible() && (grabbedimage = opencv_highgui.cvQueryFrame(capture))!=null){
frame.showImage(grabbedimage);
}
Is it possible to covert IplImage to Buffered image. Can i access pixel data from buffered image.
Thank you
You have this little code here
IplImage originalImage = cvLoadImage(image);
BufferedImage bi=originalImage.getBufferedImage();
Related
So I am trying to resize a .bmp image using the following code:
void resizeSeenAreaToFitRetina(String BMPImageFileName, int newWidth, int newHeight) throws IOException {
BufferedImage bmpImage = ImageIO.read(getClass().getResource(BMPImageFileName));
Image scaledBMPImage = bmpImage.getScaledInstance(newWidth, newHeight, Image.SCALE_FAST);
BufferedImage scaledBufferedBMPImage = (BufferedImage) scaledBMPImage; // I know I can't do this but ImageIO.write(only_takes_BufferedImage_class_here, ...)
ImageIO.write(scaledBufferedBMPImage, "bmp", new File("ResizedArray2DTest.bmp"));
}
how can I write the resized image to a file?
I hope these links helps you:
how to resize Image in java?
http://www.mkyong.com/java/how-to-resize-an-image-in-java/
http://www.mkyong.com/java/how-to-write-an-image-to-file-imageio/
Try these links
http://www.journaldev.com/615/java-image-resize-program-using-graphics2d-example
resizing image in java
How can I resize an image using Java?
I am trying to resize an IplImage image in javacv. I found the cvResize function that does such a thing. MY workflow is: to open the image to transform it to gray_scale to resize it to desirable size and finally to reshape it. I have already read it transform it to gray_scale and resize it. What is my problem the final step, reshaping. I have the cvReshape which does what I want. I ve got an IplImage, I have to transform it to cvMat. The next step is reshaping, which takes 4 arguments, a cvArr a cvMat and the desirable dimensions.
// read an image
final IplImage image = cvLoadImage("ef.jpg");
//create image window named "My Image"
final CanvasFrame canvas = new CanvasFrame("My Image");
// request closing of the application when the image window is closed
canvas.setDefaultCloseOperation(javax.swing.JFrame.EXIT_ON_CLOSE);
// show image on window
canvas.showImage(image);
IplImage GrayImage = cvCreateImage(cvGetSize(image), IPL_DEPTH_8U, 1);
cvCvtColor(image, GrayImage, CV_BGR2GRAY);
IplImage img = IplImage.create(60, 60, IPL_DEPTH_8U, 1);
//resize the image
cvResize(GrayImage, img, CV_INTER_LINEAR);
cvSaveImage("4-rjb" + ".jpg", img);
//cvReleaseImage(result1);
System.out.println("The size of the image: "+img);
CvMat mtx = CvMat.createHeader(img.height(), img.width());
cvGetMat(img, mtx, null, 0);
System.out.println(mtx);
cvReshape(img, mtx, 3600, 1);
I am receiving the error:
OpenCV Error: Bad number of channels () in unknown function, file .\src\array.cpp,
line 2721
I ve just want to reshape a 2d image, why that bad number of channels error happened??
With some Googling I found that your output matrix must contain at least 3 channels. (Blue, Green and Red). Where Blue and Green will be completely empty and you put your grayscale image as Red channel of the output image. Any other number of channels will cause the error you are getting.
I am trying to make a mood detection app in opencv, java. But there is a lag in processing the image and then displaying the emoticon. So I want to directly use the image captured , instead of copying the image to the hard disk. For that I need convert iplimage to matimage .
Try
IplImage *ipl_img;
Mat mat_img(ipl_img);
Try this
IplImage img;
bmp = Bitmap.createBitmap(img.width(), img.height(), Bitmap.Config.ARGB_8888);
bmp.copyPixelsFromBuffer(img.getByteBuffer());
Mat mROI = new Mat(new Size(img.width(), img.height()), CV_8UC4);
Utils.bitmapToMat(bmp, mROI);
i am developing android app using android sdk camera. on camera preview i need the frame content so i am using PreviewCallback to return the data in byte array, now my problem is saving the data in mat object the mat return gray images:
public void onPreviewFrame(byte[] data, Camera camera) {
Mat src = new Mat(previewSize.height, previewSize.width, CvType.CV_8U, new Scalar(255));
src.put(0, 0, data);
Highgui.imwrite("/mnt/sdcard/1.jpg", src);
}
anybody can help me to generate argb images
note: i am using NV21 in preview image format.
Do this instead:
Mat src = new Mat(previewSize.height, previewSize.width, CvType.CV_8UC3);
If it does not work, it means your data is already gray, so you must have set it as gray somewhere in your code.
I would like to create a gif image of a filled red circle on a green background. What is the easiest way to do it in Java?
If you already have an image file or image URL, then you can use Toolkit to get an Image:
Image img = Toolkit.getDefaultToolkit().createImage(filename);
If you need to construct a new image raster and paint into the image, then you can use BufferedImage. You can paint onto a BufferedImage, by calling its createGraphics function and painting on the graphics object. To save the BufferedImage into a GIF, you can use the ImageIO class to write out the image.
The best way is to generate a BufferedImage:
BufferedImage img = new BufferedImage(int width, int height, int imageType)
// you can find the Types variables in the api
Then, generated the Graphics2D of this image, this object allows you to set a background and to draw shapes:
Graphics2D g = img.createGraphics();
g.setBackground(Color color) ; //Find how to built this object look at the java api
g.draw(Shape s);
g.dispose(); //don't forget it!!!
To built the image:
File file = new File(dir, name);
try{
ImageIO.write(img, "gif", file);
}catch(IOException e){
e.printStackTrace();
}
Create a BufferedImage and then write it to a file with ImageIO.write(image, "gif", fileName).