I currently use the BufferGraphics object if I want to animate my Graphics in C#. The thing is, I would like to know how to access the data which I stored.
I use the buffer to do things like:
bufferContext = BufferedGraphicsManager.Current;
bufferGraphics= bufferContext.Allocate(g, this.DisplayRectangle);
// In some function it would then draw some rectangles or paths etcetera and call
// bufferGraphics.Graphics.FillPath(brush, path);
bufferGraphics.Render(g);
bufferGraphics.Dispose();
Question: But how can I loop through the pixels that I store in BufferGraphics?
Note: I am not allowed to show any source code, however my question should be clear to you if you ever used the bufferGraphics object.
Related
I've already tried asking the question on their forums but as yet to have received a response, hope someone can help me on here.
I have setup a custom report screen in asp.net where people can drag labels and fields and Migradoc produces this accordingly by using textframes and top/left/width/height properties to lay them out in the same place they were dragged/resized to. This all works great however one issue I have is if the text is longer than the textframe it runs off the page and I need the page to move on accordingly whilst retaining the other objects in place.
I can use the below code to measure a string:
Style style = document.Styles["Normal"];
TextMeasurement tm = new TextMeasurement(style.Font.Clone());
float fh = tm.MeasureString(value, UnitType.Millimeter).Height;
float fw = tm.MeasureString(value, UnitType.Millimeter).Width;
But it's only useful for comparing the width against the frame and not the height because it could be different once put into a smaller area. Does anyone know how I can measure this string based on bound width/height values i.e. within a text frame.
Look at the CreateBlocks() method in the XTextFormatter class and how it calls MeasureString in a loop to break the text to multiple lines.
I'm afraid you have to implement such a loop yourself.
Or maybe use the PrepareDocument() method of the DocumentRenderer class to let MigraDoc do the work and just query the dimensions when it's done.
BTW: a similar question had been asked at the forum before:
http://forum.pdfsharp.net/viewtopic.php?p=3590#p3590
Answer includes some source code.
An easy way to do this (using I-liked-the-old-stack-overflow's link) is to add the PdfWordWrapper class to your project and then calculate the dimensions of your text as follows:
var wrapper = new PdfWordWrapper(g, contentWidth); //g is your XGraphics object
wrapper.Add("My text here", someFont, XBrushes.Black);
wrapper.Process();
var dimensions = wrapper.Size; //you can access .Height or .Width
//If you want to reuse the wrapper just call .Clear() and then .Add() again with some new text
I would like to implement a multiple blob tracking algorithm,
I have a feed of bitmaps (30 bitmaps per second).
The first bitmap for example looks like this:
And the second image looks like that:
I want to be able to know that object #1 in the first image is object #1 in the second image, and so with object #2. In addition I want to want to be able the get the blob surrounding the object in the image.
The second step is very easy to implement with somthing like openCV, but to know that 2 blob are the same object is someting i couldn't succeed to implement.
My goal is to archive something like this:
Please advice,
Noam
Once you identified the blobs you can calculate each blob's moments - here is a link that shows you how using OpenCv. Then the vector of moments can be used as a descriptor for this blob. Different descriptors can then be compared (for instance by calculating the distance between them) to determine if they are similar enough to be the same object.
I am currently building an application which is able to access a number of USB webcams. I am well aware that there is no method which can count the number of camera devices on a machine, however, whenever I try to access a camera with a wrong index, I get a black image. Is there some way to use this image to denote a limit?
For example, I have two webcams. The application retrieves frames from the first camera at index 0, and from the second camera at index 1. When i increment index to 2, all I get is a black screen (obviously, since there is no 3rd camera attached).
So far the only way how to go about this is to access every single pixel in a 320x240 bitmap and check that it is black. This is not very efficient so maybe there's some other way of doing this which I am overlooking.
Thanks for your time.
An easy way would be going with openFrameworks, which has a class called ofVideoGrabber. With its listDevices() method you can list all available cams and choose the one you want to use.
Next thing you need: ofxCv is an alternative OpenCV wrapper for openFrameworks, which you can use to transfer the images grabbed by ofVideoGrabber to OpenCV or for the rest of the processing.
So you could do something like this:
// Inside Foo.h
#include "ofxCv.h"
// import namespaces for OpenCV & ofxCv
using namespace cv;
using namespace ofxCv;
// vars we need
ofVideoGrabber vidGrabber;
ofImage inputImg;
Mat matImg;
// setup video grabber
vidGrabber.setVerbose(true);
vidGrabber.setDeviceID(1); // choose the right one via vidGrabber.listDevices()
vidGrabber.initGrabber(320,240,false);
int grabW = vidGrabber.width;
int grabH = vidGrabber.height
// grab current frame
vidGrabber.grabFrame();
inputImg.setFromPixels(vidGrabber.getPixels(), 320, 240, OF_IMAGE_COLOR);
// get cv::Mat
matImg = toCv(inputImg).clone();
... further processing ...
Hope it helps!
Yes, there is method can count cameras.
you have to use directshow or directshow.net.
IEnumMoniker.
http://msdn.microsoft.com/en-us/library/windows/desktop/ms692852%28v=vs.85%29.aspx
I have a source image like left picture and a set of elements like right picture: Source Image And Elements...
..and I need to generate a mosaic picture like this.
But until this moment I have not worked with images, аnd I do not know where I should start.
I worked several years with C#, but you can give examples in other similar languages.
The result image you gave is apparently a ministeck pattern - in 2011 they had a downloadable software that seemed to do what you want. (Which is not available anymore by ministeck directly, but it seems that pfci.de still provides a download).
So, if you're just looking to generate the patterns for ministeck out of a given image, use their software. If you're after an algorithm to achieve something different, this won't help.
EDIT
Ok, if you're after analyzing your image, you need to load it into an object like this:
using(Bitmap b = new Bitmap(yourFileName))
{
MessageBox.Show(string.Format("image size {0} by {1} pixels", b.Width, b.Height));
MessageBox.Show(string.Format("color of pixel (100,100) is {0}", b.GetPixel(100, 100).ToString()));
}
The Bitmap object has several properties and methods that will help you to analyze the image content. Try this to get started with analyzing your image, and don't forget to either dispose your bitmap afterwards or wrap it into a using statement as shown above ...
How can I add an item to a list if that item is essentially a pointer and avoid changing every item in my list to the newest instance of that item?
Here's what I mean:
I am doing image processing, and there is a chance that I will need to deal with images that come in faster than I can process (for a short period of time). After this "burst" of images I will rely on the fact that I can process faster than the average image rate, and will "catch-up" eventually.
So, what I want to do is put my images into a <List> when I acquire them, then if my processing thread isn't busy, I can take an image from that list and hand it over.
My issue is that I am worried that since I am adding the image "Image1" to the list, then filling "Image1" with a new image (during the next image acquisition) I will be replacing the image stored in the list with the new image as well (as the image variable is actually just a pointer).
So, my code looks a little like this:
while (!exitcondition)
{
if(ImageAvailabe())
{
Image1 = AcquireImage();
ImgList.Add(Image1);
}
if(ImgList.Count > 0)
{
ProcessEngine.NewImage(ImgList[0]);
ImgList.RemoveAt(0);
}
}
Given the above, how can I ensure that:
- I don't replace all items in the list every time Image1 is modified.
- I don't need to pre-declare a number of images in order to do this kind of processing.
- I don't create a memory devouring monster.
Any advice is greatly appreciated.
Just reinitialize:
Replace
Image1 = AcquireImage();
with
Image1 = new Image(AcquireImage());
or just say
ImageList.Add(new Image(AcquireImage()));
Your code is correct. None of your above code affects previously added images. The line:
Image1 = AcquireImage();
puts the reference (to an image) returned from AcquireImage into the Image1 reference variable. Then:
ImgList.Add(Image1);
adds that reference to your list. Changing your Image1 reference variable does not affect references already in the list.
Conceptually, your code will be fine. The important element is that AcquireImage() allocates a new instance for each incoming image.
If Image1 were a pointer, you would have a problem - however a C# reference is not a pointer.
If I understand what you're saying correctly, you want to be able to re-use a variable without overwriting its existing data. The good news is that you don't need to change anything. You're partially correct when you say that Image1 is a pointer: it's a reference to whichever image it's pointing to at the time. When you allocate it:
Image1 = AcquireImage();
you're not overwriting the contents of the existing image, but changing the reference so it points to the new image. Assuming AcquireImage is working correctly and returns a new image every time, rather than overwriting the previous one, the above code will discard the existing reference in favour of the new one. However, as you've added it to the list already, a reference to the image is retained somewhere in your code, and so it will not be lost.