Use of imageCropAndScaleOption and regionOfInterest in VNCoreMLRequest - apple-vision

What happens if I use both imageCropAndScaleOption and regionOfInterest. What's the effect of the following codes
request.imageCropAndScaleOption = .centerCrop
request.regionOfInterest = CGRect(x: 0.0, y: 0.25, width: 1.0, height: 0.5)
request is a VNCoreMLRequest
Will the input be CGRect(x: 0.0, y: 0.25, width: 1.0, height: 0.5) with respect to the entire image or the center-cropped image?
Also I found when I just imageCropAndScaleOption to be .centerCrop, and if my CoreML model has an input of size 800x400, Vision API actually takes the largest centered square image from the camera, and resizes it into 800x400 before feeding into my model. It is different from their document:
maintaining aspect ratio to fit the short side, while cropping the centered image on its long side.

Related

QT3D Multiview - Single View in Widget

I have a question regarding the "Qt 3D: Multi Viewport QML Example" Link
Is there a possibility to add a single view (one of the four in the example) into a separate widget. I tried to change the example but I only could add all four views to one widget.
The following code creates a camera which should be displayed in a separate Widget. see Picture
I am not sure if it is possible and how i can solve it.
SimpleCamera {
id: camera4
lens: cameraLens3
position: Qt.vector3d(100.0, 0.0, -6.0)
viewCenter: Qt.vector3d(0.0, 0.0, -6.0)
}
In the example, the four views are created using the classes Viewport and CameraSelector.
The Viewport class
The class Viewport defines the portion of the screen that the branch of the framegraph (that the Viewport node is part of) is rendered to. The portion is defined as (x, y, width, height). The coordinates of the whole screen are (0, 0, 1, 1).
If you have a look at the QuadViewportFrameGraph class that is part of the example, you'll see four viewports defined - one for each camera. The top left camera renders to the rectangle (0, 0, 0.5, 0.5) of the screen. The top right camera on the other hand renders to (0.5, 0, 0.5, 0.5), i.e. it uses half of the screen size as its x offset.
The CameraSelector class
This class defines which camera the branch of the framegraph uses to render content. If you look into the example you'll see a CameraSelector { id: someCamera } within each Viewport instance. This way, each Viewport gets its own camera.
Conclusion
If you only want one view, remove the four Viewports within the main Viewport and add one camera selector as the child of it. So your QuadViewportFrameGraph should look like this (without import statements):
RenderSettings {
id: quadViewportFrameGraph
property alias camera: cameraSelector.camera;
property alias window: surfaceSelector.surface
activeFrameGraph: RenderSurfaceSelector {
id: surfaceSelector
Viewport {
id: mainViewport
normalizedRect: Qt.rect(0, 0, 1, 1)
ClearBuffers {
buffers: ClearBuffers.ColorDepthBuffer
clearColor: Qt.rgba(0.6, 0.6, 0.6, 1.0)
CameraSelector { id: cameraSelector }
}
}
}
}
Of course you also have to adjust the code where you instantiate the QuadViewportFrameGraph and only set the one camera. If you now want all four views displayed in separate widgets you need to create four 3D windows and window containers and such a framegraph for each (with different cameras of course).
But be warned that the performance might be crappy if you create for distinct 3D windows. As far as I know, there are no other solutions to obtain 3D widgets.

Dynamically change plane height in babylonjs

I created a plane by using
this.plane = BABYLON.MeshBuilder.CreatePlane("plane", { width: 0.5, height: 10 }, scene, true);
and then I try to modify the plane height in rendering, but the height is not changed.
I think you are looking for scaling. Here is the link to Babylon.js Scaling. Essentially, you do
objectName.scaling.x = 1.50 //This is a scaling multiplier (you can substitute x, y, and z)
//Or, if you want to scale in more than one direction, you can use a vector3
objectName.scaling = new Babylon.Vector3(1.5,.5, 2)
This should let you dynamically change the dimensions of your object. If you wanted the make the change visibly noticeable (instead of jumping straight to the correct size) you could also add an animation to it.

How do we translate a QML Rectangle on the Z axis, not just X and Y?

Is it possible to translate a QML Rectangle on the Z axis similar to how we can do in HTML with CSS transform:translateZ() and transform:translate3d()?
Applying transform: Translate {x: 0; y: 0; z: 100} on a Rectangle throws an error that the z property isn't defined.
I am able to apply transform: Rotation{} to a Rectangle with a z-axis rotation and it looks 3D. I was hoping I could translate things in 3D as well.
Is there a way to do it?
EDIT: I tried setting a Matrix4x4 like this:
transform: Matrix4x4 {
matrix: Qt.matrix4x4(
1,0,0,0,
0,1,0,0,
0,0,1,10,
0,0,0,1
)
}
I set the number 10 where I believe the Z translation is, but the Rectangle just disappears instead of getting a little closer to the camera.
Applying transform: Translate {x: 0; y: 0; z: 100} on a Rectangle throws an error as expected as Translate only has only x and y properties (See http://doc.qt.io/qt-5/qml-qtquick-translate.html).
The Transform does not correspond with how you are trying to use it as z is not the position along the z-axis. z is the "stacking order" which is used to control which items are drawn on top or below other items (http://doc.qt.io/qt-5/qml-qtquick-item.html#z-prop).
If you wanted to let your Rectangle appear "a little closer to the camera", Scale seems like a possible Transform to use (http://doc.qt.io/qt-5/qml-qtquick-scale.html) or just use the item's scale property (http://doc.qt.io/qt-5/qml-qtquick-item.html#scale-prop).
This answer might also be helpful to you as someone else had a similar question. It illustrates how you can rotate along different axis. For example, You could do something like: transform: Rotation { origin.x: 50; origin.y: 55; axis { x: 0; y: 1; z: 0 } angle: 60}.
Note though that it is not possible to actually translate a QML Rectangle along the "z-axis". So if your goal is to create a 3D scene in QML, two possible options are Qt Canvas3D or the Qt3D module. If you want to use three.js check out this post

Drawing to the left of x,y coordinates

I'm working currently on Qt, when i try to draw something (for e.x Rectangle) giving its x,y coordinates & its width & height Qt starts to draw the rectangle starting from its x, y coordinates to the right direction, to demonstrate what I'm talking about see the following picture:
and the following code:
Rectangle {
id: rectangle1
x: 257
y: 221
width: 50
height: 50
color: "#000000"
}
I would like to know if there is anyway i can start drawing to the left of x,y coordinates, it's like drawing giving the width & height negative values. see the following image for illustration:
I have tried drawing giving the width a negative value, it works fine on the design mode but when i run or debug my application the rectangle does not show up, any ideas on this would be appreciated
You can not use negative values for this purpose since negative width or height is not supported in QML. But you can use Scale type to accomplish this :
Rectangle {
id: rectangle1
x: 257
y: 221
width: 50
height: 50
color: "#000000"
transform: Scale { origin.x: 0; origin.y: 0; xScale: -1}
}
Scale allows you to scale your item relative to an arbitrary point. Here we scaled the X axis of the item relative to it's interior point (0, 0).
To draw rectangle 50px from the left parent area:
Rectangle {
id: rectangle1
x: parent.width - 50 // rectangle start 50px from the left
y: 221 // similar with y pos: parent.height - 50
width: 50
height: 50
color: "#000000"
}
But I am not sure If I understood your question properly.

How do I set the variables for setSelect to get a full preview of an image with jCrop?

I want to have full preview for image, but it's giving me 70% of the image.
What should I do with the x2 and y2 variables for setSelect?.
jQuery('#preview').Jcrop({
minSize: [32, 32], // min crop size
aspectRatio: 1, // keep aspect ratio 1:1
bgFade: true, // use fade effect
bgOpacity: .3, // fade opacity
//setSelect: [0, 0, 768, 540],
//setSelect : [0,Math.round($('#preview').height()),Math.round($('#preview').width()/200),Math.round($('#preview').height()/200)],
setSelect : [0,0,Math.round($('#preview').width()),Math.round($('#preview').height())],
onChange: updateInfo,
onSelect: updateInfo,
onRelease: clearInfo
}
You should check the div.jcrop-holder with object inspector of your browser. Definitely its width is not 100%. It can caused by your CSS code so you should find the problem there.
If you see that the div.jcrop-holder has style property and the width is set you need to set boxWidth option. For further information see the relevant page of the documentation: http://deepliquid.com/content/Jcrop_Sizing_Issues.html

Resources