OpenLayers version 5.3.0, problem on map export pdf - version

I use openlayers version 5.3.0 and I want to export map pdf. The problem is that map extent on export isn't correct. It prints wrong height. At the openlayers (version 5.3.0) examples(https://openlayers.org/en/v5.3.0/examples/export-pdf.html?q=pdf) the result is the same as mine. The printed map height is more than map's extent. I checked also the same at the latest version (https://openlayers.org/en/latest/examples/export-pdf.html) and that is absolutely correct. It prints exactly the map extent. How can I fix it on my version without having to change version?
Thanks in advance.
// Reset original map size
map.setSize(size);
map.getView().fit(map.getView().calculateExtent(map.getSize()), {constrainResolution: false});
map.getView().setResolution(viewResolution);
document.body.style.cursor = 'auto';
// Set print size
let printSize = [width, height];
map.setSize(printSize);
let scaling = Math.min(width / size[0], height / size[1]);
map.getView().fit(map.getView().calculateExtent(map.getSize()), { size: printSize , constrainResolution: false});
map.getView().setResolution(viewResolution/scaling);

Related

Problem with NumPy Arrays when creating Face Filters

I am currently working on a project where I detect a face with a haar cascade classifier.
In the code, I have created Rois with a cv2 rectangle and the goal is to apply images to the ROI. On some images the code works on others it doesn´t, also applying filters doesn´t work on videos or on my webcam.
The Error Code:
ValueError:
could not broadcast input array from the shape (50,70,3) into shape
(50,2,3)
Here are some code lines that may be important:
#Reading the image
image = file dialog.askopenfilename(initialdir="/Pictures", title="select a file", filetypes=(("png files", ".jpg", ),("all file", ".*")))
img = cv2.imread(image)
gray = np.array(img)
How the Roi is created and the filter applied.
visual_eye_r = cv2.rectangle(grayef, (x,y), (x+w, y+h), (255, 255, 255, 0), )
ROI_2 = visual_eye_r[y:y+h, x:x+w]
imagefilter = cv2.imread("filter.png")
roi_h, roi_w = ROI_2.shape[:2]
image_h, image_w = imagefilter.shape[:2]
#Calculate height and width offsets
height_off = int((roi_h - image_h)/2)
width_off = int((roi_w - image_w)/2)
#Mit Numpy Slicing Bild überlegen
ROI_2[height_off:height_off+image_h, width_off:width_off+image_w] = image8
Have already looked elsewhere for the same issue but none of the fixes worked. Maybe someone can help me understand or fix the issue, because i am relative new to python.
Issue has been fixed. Realised that the height and width offset was negative, because of the size of some Region of Interests. That was what caused the error.

Codename One: how to get the width in millimeters of a component?

I created an app to calculate the sizes of a multi-image, in order to use them in the Codename One designer.
As you can see in the screenshot below, my app has a slider and I get the width (in millimeters) of it. The problem is that the value of the selected width is incorrect. I tested the app on two Android devices and the measured lengths are different from the ones reported by the app.
You can see the full source code, however the relevant code is the following:
Label value = new Label("Move the cursor on the slider...");
Style thumbStyle = new Style();
thumbStyle.setFont(Font.createSystemFont(Font.FACE_MONOSPACE, Font.STYLE_BOLD, Font.SIZE_LARGE), true);
Slider slider = new Slider();
slider.setMaxValue(1000);
slider.setMinValue(0);
slider.setProgress(20); // Set the starting value
slider.setThumbImage(FontImage.create("|", thumbStyle));
slider.setEditable(true); // to it works as a slider instead of a progress bar
slider.addActionListener(e -> {
Integer valueSelected = slider.getProgress();
Integer sliderWidth = slider.getWidth();
Double inch = sliderWidth.doubleValue() / (slider.getMaxValue() - slider.getMinValue()) * valueSelected / 100.0;
Integer millimeters = Double.valueOf(inch * 25.4).intValue();
value.setText("Value selected: " + millimeters.toString() + " mm");
});
Thank you very much for any help
Millimeter measures aren't accurate. A device can return different values or ratios for the convert method than the value it returns for the density flag.
Unfortunately, Googles test suite to certify a device as "good" doesn't actually cover these things. There isn't much we can do about that.

Listen for click / hover on individual axis labels

I'm looking for a way to change the value (or format) for an individual series label when hovering it in anycharts.
Currently I'm only able to access the entire axis and I can find no getter method for individual labels so as to attach a listener.
xAxis.labels().listen('mouseOver', function(e) {
console.log(this, e.target);
});
This jsfiddle is as far as I got (see console log), this as well as the event.target reference the entire axis but not the label:
https://jsfiddle.net/robstarbuck/pbhd4b7L/9/
Indeed, there was a little bug with cache and format() function, our dev team made the fix, so please check the working sample:
var labelIndex = e.labelIndex;
var label = this.getLabel(labelIndex);
var value = xAxis.scale().ticks().get()[labelIndex];
label.format(value * 2);
https://jsfiddle.net/pbhd4b7L/13/ – it also shows how to work with tick values:
Currently it takes the js from branch, but this fix will be included in the upcoming release – 7.14.0 version (ETA: May 2017)
Our API is a little bit complicated here, but we're working hard to improve it. Does this what you're looking for?
var labelIndex = e.labelIndex;
var label = this.getLabel(labelIndex);
label.fontColor('red');
label.draw();
https://jsfiddle.net/pbhd4b7L/10/
This issue was fixed in the 7.14.0 release, use this code:
xAxis.labels().listen('mouseOver', function(e) {
var labelIndex = e.labelIndex;
var label = this.getLabel(labelIndex);
var value = xAxis.scale().ticks().get()[labelIndex];
label.format(value * 2);
label.fontColor('red');
label.draw();
});
with the latest version: https://jsfiddle.net/2t08ahkg/3/

Codename One rounded image from an internet source

I am trying to display a rounded image that I get straight from the Internet.
I used the code below to create a round mask, get the image from the Internet, then tried to either set the mask on the image or the label itself. None of these approaches worked. If I remove the mask, the image is displayed fine. If I keep the code to set the mask then all I see is an empty white circle.
I have the idea that if I apply the mask on the image itself, then it may not take effect because the image was not downloaded at the time the mask was applied.
But I don't seem to understand why calling setMask on the label is also not working.
// Create MASK
Image maskImage = Image.createImage(w, l);
Graphics g = maskImage.getGraphics();
g.setAntiAliased(true);
g.setColor(0x000000);
g.fillRect(0, 0, w, l);
g.setColor(0xffffff);
g.fillArc(0, 0, w, l, 0, 360);
Object mask = maskImage.createMask();
// GET IMAGE
com.cloudinary.Cloudinary cloudinary = new com.cloudinary.Cloudinary(ObjectUtils.asMap(
"cloud_name", "REMOVED",
"api_key", "REMOVED",
"api_secret", "REMOVED"));
// Disable private CDN URLs as this doesn't seem to work with free accounts
cloudinary.config.privateCdn = false;
Image placeholder = Image.createImage(150, 150);
EncodedImage encImage = EncodedImage.createFromImage(placeholder, false);
Image img2 = cloudinary.url()
.type("fetch") // Says we are fetching an image
.format("jpg") // We want it to be a jpg
.transformation(
new Transformation()
.radius("max").width(150).height(150).crop("thumb").gravity("faces").image(encImage, "http://upload.wikimedia.org/wikipedia/commons/4/46/Jennifer_Lawrence_at_the_83rd_Academy_Awards.jpg");
Label label = new Label(img2);
label.setMask(mask); // also tried to do img2.applyMask(mask); before passing img2
So I tried various things:
1) Removing the mask that was set through cloudinary - That did not work
2) applied the mask to the placeholder & encoded image (as expected these shouldnt affect the final version that is getting published)
3) This is what works! I am not sure if the issue is really with downloading the picture before or after applying the mask.. time can tell down the road
Label label = new Label();
img2.applyMask(mask); // If you remove this line , the image will no longer be displayed, I will only see a rounded white circle ! I am not sure what this is doing, it might be simply stalling the process until the image is downloaded? or maybe somehow calling repaint or revalidate
label.setIcon( img2.applyMask(mask));
Here is what worked for me if anyone else is having similar issues:
//CREATE MASK
Image maskImage = Image.createImage(w, l);
Graphics g = maskImage.getGraphics();
g.setAntiAliased(true);
g.setColor(0x000000);
g.fillRect(0, 0, w, l);
g.setColor(0xffffff);
g.fillArc(0, 0, w, l, 0, 360);
Object mask = maskImage.createMask();
//CONNECT TO CLOUDINARY
com.cloudinary.Cloudinary cloudinary = new com.cloudinary.Cloudinary(ObjectUtils.asMap(
"cloud_name", "REMOVED",
"api_key", "REMOVED",
"api_secret", "REMOVED"));
// Disable private CDN URLs as this doesn't seem to work with free accounts
cloudinary.config.privateCdn = false;
//CREATE IMAGE PLACEHOLDERS
Image placeholder = Image.createImage(w, l);
EncodedImage encImage = EncodedImage.createFromImage(placeholder, false);
//DOWNLOAD IMAGE
Image img2 = cloudinary.url()
.type("fetch") // Says we are fetching an image
.format("jpg") // We want it to be a jpg
.transformation(
new Transformation()
.crop("thumb").gravity("faces")
.image(encImage, url);
// Add the image to a label and place it on the form.
//GetCircleImage(img2);
Label label = new Label();
img2.applyMask(mask); // If you remove this line , the image will no longer be displayed, I will only see a rounded white circle ! I am not sure what this is doing, it might be simply stalling the process until the image is downloaded? or maybe somehow calling repaint or revalidate
label.setIcon( img2.applyMask(mask));
Shai, I seriously appreciate your time!! Thank you very much. Will have to dig more into it if it gives me any other problems later but it seems to consistently work for now.
The Cloudinary API returns a URLImage which doesn't work well with the Label.setMask() method because, technically, a URLImage is an animated image (it is a placeholder image until it finishes loading, and then "animates" to become the target image).
I have just released a new version of the cloudinary cn1lib which gives you a couple of options for working around this.
I have added two new image() methods. One that takes an ImageAdapter parameter that you can use to apply the mask to the image itself, before setting it as the icon for the label. Then you wouldn't use Label.setMask() at all.
See javadocs for this method here
The other method uses the new Async image loading APIs underneath to load the image asynchronously. The image you receive in the callback is a "real" image so you can use it with a mask normally.
See javadocs for this method here
We are looking at adding a soft warning to the Label.setMask() and setIcon() methods if you try to add an "animated" image and mask it so that it is more clear.
I think the making code you set to the label might be conflicting with the masking code you get from Cloudinary.

Segmented control tintColor in iOS 6

I have a segmented control with 8 segments. I can change the default tint-color of the whole control, BUT can I set a different color for each segment in the control? I found a tutorial that worked in 5.1 with a new class that calls this method,
-(void)setTintColor:(UIColor*)color forTag:(NSInteger)aTag{}
But it doesn't work in iOS 6. Any ideas?
This issue has been fixed here. I could not paste the source code due to formatting issues.
Sample code here.
EDIT: added comment & code from link and fixed formatting. ~olie
Its a hacky fix. This will work. Place your code in ViewDidAppear. That will do the trick.
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear: animated];
dispatch_async(dispatch_get_main_queue(), ^{
for (int i = 0 ; i < [segmentControl.subviews count] ; i++)
{
if ([[segmentControl.subviews objectAtIndex: i] isSelected] )
{
[[segmentControl.subviews objectAtIndex: i] setTintColor: [UIColor blackColor]];
break;
}
}
});
}
You can set different segment image and color for each segment. For color you may use:
//get the subviews of the segmentedcontrol
NSArray *arri = [segmentedControl subviews];
//change the color of every subview(segment) you have
[[arri objectAtIndex:0] setTintColor:[UIColor redColor]];
[[arri objectAtIndex:1] setTintColor:[UIColor greenColor]];
Hope that solves the problem.
You are right...
iOS 6 doesn't support subviews for segmented control....
I have an alternative for you:
CGRect rect = CGRectMake(0, 0, 80, 44);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context,
[[UIColor redColor] CGColor]);
CGContextFillRect(context, rect);
UIImage *img = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
[segment setImage:img forSegmentAtIndex:0];
You need to have core graphics framework added to the project.
We can draw an image for segment at index.... But if you use this, you won't be able to add text using segment title. You will need to draw text also over the image 'img' used above.
Please share if you get any other way of doing it.
UiSegmentedControl has a property 'segmentedControlStyle' (deprecated in iOS7) that affect the behavior of 'tintColor'
the possible styles are:
UISegmentedControlStylePlain,
UISegmentedControlStyleBordered,
UISegmentedControlStyleBar,
UISegmentedControlStyleBezeled,
but actually in iOS6 'Bezeled' (deprecated) is equal to 'Bar'
with the first two styles there is no way to change have applied the 'tintColor', to customize it you need to change the images for each segment using:
- (void)setImage:(UIImage *)image forSegmentAtIndex:(NSUInteger)segment;
in this way you will obtain a completely custom segmented control
But if the defaul is enough for your design you can just use the style
UISegmentedControlStyleBar
and the 'tintColor' property will take effect and you will obtain a colored segmented control applying the tint depending to the selected segment and all the other benefits letting the system dial with it.
Here is an easy solution setting a red color and compatible with iOS 6.
for ( UIView *segmentView in [segmentedControl subviews] ) {
if ( [segmentView respondsToSelector:#selector(setTintColor:)] ) {
[segmentView performSelector:#selector(setTintColor:)
withObject:[UIColor redColor]];
}
}

Resources