Creating and Saving an image in C++ VS - c++

My question in brief:
I have many coordinates points(x,y) which needs to be drawn and saved as a picture in a folder. I need to write codes using C++.
Detailed Explanation:
Let's say i have n coordinate points(x ,y). I have two functions namely the "jump" and the "mark".
The function call would be in this sequence always:
jump(x,y)
mark(x,y)
jump(x,y)
mark(x,y)
..............this sequence happens till all coordinate points are considered finished.
1)The first Jump function will point to the current coordinate position/start position.
2)All mark functions would draw a continuous line from the previous jump function coordinates to the the coordinates it received.
3)Rest of the jump functions(except the first jump function) would draw a dotted line/dashed line from the previous mark coordinates till the coordinates it received. So this line would tell us from where did the jump function jumped to draw the next mark line(Refer attached Picture for better clarity)
How do i implement it?
Any graphic libraries in C++ available to perform simple plotting and saving of an image like i wanted?
I read about few graphics libraries like SDL, OpenCV, OpenGL, PNGWriter.
But not sure what and how to use.
I have shown a small example of what i wanted to do, which is attached as an image.
Click here for the Image

I work with opencv, but it not support dash line while in this link there is a guide for dash line in opencv dotted line and dotted and dashed rectangle in OpenCV, for your program, you can create an white image with desired size and draw line by charactrize the start and end point coordinate and apply function:
Line draw
You can store the latest point's coordinate in a Point variable....

I suggest you use the Allegro, it's much more simple and lighter than OpenCV. I believe it will be more agile for this.
This link you can find the binaries (~44MB) for VS (select the appropriate for your vesrion).
Extract the zip file. You will see the include\, lib\ and bin\ directories. Link them appropriately in Visual Studio (this is the complete tutorial).
Here you will have the basics of reading, writing and displaying an image (Bitmaps).
I think the function al_draw_line() will help you on this specific task.

Related

Constructing a volume out of RGB value and (x,y,z) location for all pixels

In the past few days I have searched all over google for a clear explanation on how to face my project's last and great challenge in order to finish it.
I have an array of opencv colored Mat, each represents one slice of a 3d-model.
And I need to be able to display a 3d-model build from these slices.
(I can undo the entire use of opencv because I have the rgb and (x,y,z)-values of all pixels , I just thought it would be easier to transform openCV::Mat to another external library's object in order to build the volume).
To be more clear, I have an RGB value and (x,y,z) position for every pixel that will construct the 3d-model and I need a way to display them all together as a 3d-model.(I think that means to build a volume but I'm not sure)...
Any use of external library is allowed and recommended.
I'm working on visual studio 2013(community version) and writing on C++.

Pattern matching/recognition library for vectors (like OpenCV for image input)

Does anyone know a good pattern matching/recognition library in C++ (oss preferred) that is able to detect whether a list of vectors is an arrow or some other class?
I already know OpenCV but this is meant to be used for raster graphics (or did I missed something?)... but I already have a vector geometry and it sounds strange to convert them back into a raster graphic where you have to detect the edges again.
So what I need is a library that uses a list of vectors as input instead of a raster graphic and can recognize if the vectors are an arrow (independent from the direction) and extract the parts of the arrow (head/tip/tail etc.).
Anyone who knows such a lib or has a hint where to look for this kind of problem (algorithms etc.)?
I try to change the way a UI is used. I already tried protractor algorithm and divided the recognition step into different parts, e.g. for arrow example:
draw, stop drawing and take result
treat first line as body (route line, arrow shaft)
wait for accept (=> result is recognised as simple line replace hand drawn graphic with route graphic) or next draw process
draw arrow head and take result coordinates
wait for accept/finish button (=> result is recognised as arrow and is no simple route)
a) replace hand drawn vectors by correct arrow graphic
b) or go on with any fletchings? bla, bla, bla
But I want to do this in a single step for all vector lines (regardless of the order and direction). Are there any recommendations?
And what if the first is a a polyline with an angle and there is also a recognition of a caret but the follow up symbology needs to decide between them?
I want to draw commands instead of searching it them in a burdened menu. But it is important to detect also the parts of a graphic (e.g. center line, left line, ...) and keep aspect ratio (dimension) as far as it is possible, which means that key coordinates should be kept, too (e.g. arrow tip). This is important for replacing the hand-drawn vectors with the corrected standard graphic.
Is this possible with a lib as a single task or should I stay at the current concept of recognising each polyline separately and look at the input order (e.g. first line must be the direction)?
You can look here to get an idea: http://depts.washington.edu/aimgroup/proj/dollar/
There is the $1 Recognizer algorithm and some derived ones and you can try them online.
The problem is, that my "commands" consists of multiple lines and every line might have a different special meaning in the context to get the complete graphic. The algorithms and libraries I already know (like the $1 Recognizer above) are more related to single gestures instead of a complex order of multiple gesture inputs which gets the precise meaning if interpreted as a whole sketch.
I think continuing with the interpretion of each line separately and not puting it into the whole context (recognise the whole sketch) could lead to a dead end. But maybe a mixed approach might get it.
Real life comparism: It is like when somebody draws a horse. You wouldn't say it is a horse if he just started to draw the first line - you'll need some more input, e.g. 4 legs etc.
(Well, I know not everyone is good in drawing and some horses could look like cows... but anyway, this should give you an idea what I mean.)
Any hints?
Update: I've found a video here that is close to the problem. The missing link is how parts of the structure are accessible after the recognition but this can be done in a separate step, too (after knowing what the drawing shows).
In my humble opinion I'don't think that there's a library in the wild that fulfils such specific needs. In the end you'll end up writing custom code.
Either way, the first thing you'll have to do is to extract classification features from every gesture you detect. You'll have then to put your acquired feature vectors in a feature space. Once you do this, there are literally a million things you can do in order to classify the feature vectors to one of the available classes (e.g., arrow, triangle etc.). For example, the guys from the University of Washington in the link you've supplied are doing their feature extraction in steps 1,2 and 3 and they classify the acquired feature vector in step 4.
The idea of breaking the gesture into sub-gestures sounds tempting, though I have a suspicion it will introduce problems in a matter of ways (e.g., how to detect the end of a sub-gesture and the beginning of the next) and it will also introduce a significant overhead
since you will end up in additional steps and a short of a decision tree structure.
One other thing that I forgot to mention above is that you will also need to create a training data-set of a reasonable size in order to train your classifiers.
I won't get into the trouble of suggesting libraries, classifiers, linear algebra packages etc. since this is out of the scope in the first place (i.e., kindly I would suggest to search the web for specific components that will help you build your application).

Simple Algorithm For Line Curving

I'm looking for a simple algorithm for line curving (much like fireworks freeform tool).
In my C++ program, a line is a set of ordered points, each point is of (x,y) form.
Assume I have straight line of 5 (just for simplicity) ordered points (the line isn't necessarily parallel to any axis). I pinch the 3rd point and drag it up. I'm expecting to have a new, gaussian-like, curved line. It doesn't really matter how I implement the "Points" and "Lines", but keep in mind I should add more points to the new expected line so it'll be curved, refined and flowing (and not with line breaks).
I thought of using a gaussian function but I need the ability of moving the curved part (see picture below).
Thanks in advance!
You need a B-spline or a Bezier curve to approximate your shape.
There is a nice interactive demo of Bezier splines so you can play with to see the effect. A sample screenshot below:
Depending on your OS and development environment, there are probably already a number of tools or APIs available.

OpenCV C++ Drawing and Analyzing Line

I am working on a OpenCV program capable of detecting Boxers punches and categories them. At the moment my program goes through all the different image processing, finds and detects contours, draws bounding boxes on ROI's (Region Of Interest), I am also computing some properties of each bounding box such as: Area and Center Point.
Now what i want to do is to draw a line from each bounding box starting from the center point and analyze that line for its Angle and Length. Have a look at the Image that illustrates my aim:
So hopefully now you guys have a better overview........
My Question here is How do i draw such line from starting position to end position store it in a vector to analyse it...?
I did some research on various functions that draw lines but non of them seem to be appropriate for my purpose. Here are some Research links:
Opencv Draw Line & Line iterator & poly lines
Also looked at arcLength, fitLine, clipLine & Hough transform
Could some one indicate me which technique would best fit my aim...?
Some good read, examples, Or just suggest how to even start this whole thing
Regards Hopefully my problem is well understood by now
Store the centroid positions frame-by-frame of an object being tracked in an array, then feed it to the PolyLines() function.
We can use PolyLines as following:
polylines(img /*image where to plot*/, &points /*the points (centroids in your case)*/ ,&numPoint /*number of points*/,1,false /*contour is not closed shape*/, Scalar(255,255,255),3, CV_AA, 0);
-Pay attention that points must be defined as Mat

Some logic to extract image pattern from video using OpenCV

I am familiar with openCV, a powerful open source library and using that I am dealing with farm industry project where a mouse will be injected with drug , and its been kept on so called a stage which is surrounded by cylinder with painted strips of successive white and black. So i need to find out how many times the mouse will rotate its head to words the rotation of the cylinder . (its because it has got hang of drug) . How can i achieve this any opencv experts can help me out there.
I have added an image below
Seems an interesting one, these are my preliminary suggestions...
Depends on the resolution of the camera and how far your object (mouse) is from the camera...coz mouse is a small object so the image of the mouse need to cover good number of pixels in the image to differentiate head movement...
I don't think the mouse will stick to one position..it will keep moving in the cage...so you need to track the mouse...
At every position of the mouse you need to find the position of the head with respect to the body....that you can do using template matching (create templates of the head of the mouse)
Hence more info and some sample pictures are necessary to get the clear idea of the scene
EDIT AFTER IMAGE UPLOADED
since the camera is fixed hence create a circular region of interest...so that only movement inside this circle concerns you and not the moving cylinder outside the circle
subtract the present frame from the previous frame (frame differentiation) and store the absolute of the difference in an image.
absdiff(frameNow,framePrevs,diffofFrames);
threshold the diffofFrames as required to get the current position of the rat...
Now the task is easier if the image clearly shows its nose...since the nose has a pointed shape it can be detected by some template matching....however from the image you have given its difficult to make out the nose against a black background...However I can only suggest you the following process... green circles denote the tip of the nose...all I am trying to do is to get orientation of the head w.r.t. the body....for good results you need to have good images...