Comments (28)
And then maybe answer this question:
http://stackoverflow.com/questions/34440429/draw-a-line-in-a-bitmap-possibly-with-piston
; )
from imageproc.
I added a simple Rust implementation of the Bresenham algorithm to the StackOverflow question: http://stackoverflow.com/a/34722500/284318
I'd be interested in giving this issue a stab. @theotherphil can you give me some starting point on where in the library I'd add something like that, and what stucts the function would operate on? Or in other words, what should the API look like?
from imageproc.
Also, drawing a line with a thickness is probably just a specialization of filled rectangle drawing, right?
from imageproc.
Sorry for the triple post, but I dug deeper in the docs and found some functions that are already present. Aren't these already covering the issue?
Drawing a line: imageproc::drawing::draw_line_segment
Drawing a thick line: imageproc::drawing::draw_filled_rect
from imageproc.
Can't get it to work though:
extern crate image;
extern crate imageproc;
use image::RgbImage;
use imageproc::rect::Rect;
use imageproc::drawing::draw_filled_rect;
fn main() {
let mut img = RgbImage::new(256, 256);
let thickness = 10;
draw_filled_rect(&img, Rect::at(128, 10).of_size(118, thickness), [240, 240, 255]);
img.save("output.png").unwrap();
}
Results in:
src/main.rs:16:5: 16:21 error: the trait
image::image::GenericImage
is not implemented for the typeimage::buffer::ImageBuffer<image::color::Rgb<u8>, collections::vec::Vec<u8>>
[E0277]
src/main.rs:16 draw_filled_rect(&img, Rect::at(128, 10).of_size(118, thickness), [240, 240, 255]);
^~~~~~~~~~~~~~~~
I'm not sure how I can use an RgbImage
as a GenericImage
.
If I find out, maybe I can contribute some docs with examples.
from imageproc.
There's only support for axis-aligned rectangles, so we still need to add code for slanted wide lines.
Your compiler error might just be because you're missing a "use image::GenericImage". If that doesn't work I'll check when I get home (about five hours from now).
More examples in the docs would be great, even if this approach doesn't end up solving the original problem.
from imageproc.
Your compiler error might just be because you're missing a "use image::GenericImage".
No, that didn't help.
from imageproc.
Ah, the last parameter to draw_filled_rect should be Rgb([240, 240, 255]), instead of just the array.
from imageproc.
That didn't solve the problem either :(
use image::{Rgb, RgbImage};
// ...
fn main() {
// ...
draw_filled_rect(&img, Rect::at(128, 10).of_size(118, thickness),
Rgb([240, 240, 255]));
// ...
}
Same output as above.
from imageproc.
Ok, I'll have a look when I get home.
from imageproc.
Very odd. The following code works fine for me:
extern crate image;
extern crate imageproc;
use image::{
Rgb,
RgbImage
};
use imageproc::rect::Rect;
use imageproc::drawing::draw_filled_rect_mut;
fn main() {
let mut img = RgbImage::new(256, 256);
let thickness = 10;
draw_filled_rect_mut(&mut img, Rect::at(128, 10).of_size(118, thickness), Rgb([240, 240, 255]));
img.save("output.png").unwrap();
}
(Your code compiled too, but didn't do anything useful - I've replaced the use of draw_filled_rect with draw_filled_rect_mut so that we update the image in place.)
from imageproc.
Are you trying this in a new project? If so, what does your Cargo.toml file look like?
from imageproc.
I copy-pasted your code and still get the same errors :(
I'm using latest versions of both image
and imageproc
. Used *
version specifiers for quick testing:
[package]
name = "img"
version = "0.1.0"
authors = ["..."]
[dependencies]
image = "*"
imageproc = "*"
Maybe you're on a different version?
from imageproc.
For some reason
image = "*"
resulted in cargo producing a gigantic wall of complaints around not being able to find packages. However, with
image = "0.3.15"
imageproc = "*"
I can compile and run successfully on latest stable, latest nightly, and nightly from the end of last year.
from imageproc.
You're right, it works with image 0.3.15
. The current verision of image
is 0.6.1
though. Could imageproc
maybe be updated to support that version? And/or could/should important imports from image
be re-exported?
from imageproc.
Yes, it's pretty embarrassing that this doesn't work with more recent versions of image. I'd not noticed as I was using a fixed version of image. The breaking change looks to happen between 0.3.15 and 0.4.1.
from imageproc.
This works with latest image:
extern crate image;
extern crate imageproc;
use image::{
Rgb,
RgbImage,
GenericImage
};
fn constraints<I>(image: &I, color: I::Pixel)
where I: GenericImage,
I::Pixel: 'static
{
let x = image.height();
println!("{}", x);
}
fn main() {
let img = RgbImage::new(256, 256);
constraints(&img, Rgb([0, 0, 0]));
}
Where where I'm using the same bounds as the draw_filled_rect function. So I'm none the wiser as to what's going on.
from imageproc.
@bvssvni @tafia Am I missing something obvious here?
from imageproc.
When I do a cargo clean
then cargo build --verbose
it apparently compiles 2 versions of several crates
- png (0.4.1 and 0.3.1)
- image (0.6.1 and 0.3.15)
- byteorder (0.4.2 and 0.3.13)
- bitflags (0.3.3 and 0.4.0)
If I force using image 0.6.1 (via .cargo/config
file) the code works fine.
I suppose there is some conflict somewhere.
I also noted that there is a commit in image:
e7fd748 Fixed `NotEnoughData(..)` => `NotEnoughData`
which corresponds to the first warning messages I have.
EDIT: Looking at Cargo.lock is actually much simpler than using --verbose ...
from imageproc.
@theotherphil I think the issue is in your Cargo.toml / Cargo.lock => you should probably upgrade to higher version.
It specifically mentions it uses image 0.3.15. You should update the dependencies it and push it to crates.io.
[[package]]
name = "imageproc"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
dependencies = [
"conv 0.3.1 (registry+https://github.com/rust-lang/crates.io-index)",
"image 0.3.15 (registry+https://github.com/rust-lang/crates.io-index)",
"itertools 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)",
"nalgebra 0.3.2 (registry+https://github.com/rust-lang/crates.io-index)",
"num 0.1.30 (registry+https://github.com/rust-lang/crates.io-index)",
"quickcheck 0.2.24 (registry+https://github.com/rust-lang/crates.io-index)",
"rand 0.3.13 (registry+https://github.com/rust-lang/crates.io-index)",
]
from imageproc.
Any news? Any plans to fix/implement this?
I am looking for functionality similar to http://chunkypng.com/
Any plans to implement such functions/interface?
from imageproc.
I had a quick look at the documentation for that library and couldn't see anything about drawing anti-aliased lines. Which functions specifically did you have in mind?
If you're just after PNG loading and saving then this is already supported by the image library (whose image types and traits this library uses).
from imageproc.
For example this method - http://www.rubydoc.info/github/wvanbergen/chunky_png/ChunkyPNG/Canvas/Drawing#line_xiaolin_wu-instance_method
from imageproc.
Aha, thanks. I'll add that and the polygon function this weekend.
from imageproc.
Wow. That will be really great. Thanks a lot.
from imageproc.
I've made a start in #140. Take a look and let me know what you think. It's not as fast as it should be at the moment, but is hopefully correct. Is this good enough for your current use case? The initial aim of all the drawing functions was just to show points of interest on an image when debugging or verifying results of some vision algorithms, so none of them are particularly well written. This can certainly be improved though.
I'm afraid I won't get time to implement the polygon algorithm this weekend after all.
from imageproc.
Fixed by 142 and 144
from imageproc.
Works for me. Thanks.
from imageproc.
Related Issues (20)
- initialization of `morphology::Mask` HOT 6
- Rename arguments of `assert_pixels_eq` HOT 6
- "cannot find trait `FontRef` in this scope" HOT 2
- Remove top-level clippy allows HOT 2
- Remove non-`_mut` function variants. HOT 10
- `warp_inner()` and `equalize_histogram_mut()` should be two functions based on `rayon` feature HOT 1
- migrate from `quickcheck` to `proptest`
- How does this crate compare to magick-rust? HOT 2
- Try using doc_auto_cfg to automate addition of docrs attributes
- Rename `imageproc::map::map_colors()` to `map_pixels()` HOT 2
- Another doc-macro for parallel variations of functions?
- `Rect` refactors HOT 2
- Add filter benchmarks for kernels larger than 3x3
- Add hardcoded filter3x3 function to benchmark current generic filter function against HOT 19
- Switch `imageproc::Rect` to `image::Rect` HOT 3
- `Laplacian` from `master` is wrong HOT 4
- Check for any functions missing tests
- Use `Kernel` by `ref` HOT 2
- Document release process
- Agree a sensible API for filtering so we can reduce the risk of frequent breaking changes to signatures HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from imageproc.