How can I change the tip_width and tip_height of NumberLine? (manim v0.15.2) - manim

(Hi. This is my very first question on stack overflow so please let me know if the question is unclear.)
I am trying to make the arrowhead of a NumberLine mobject smaller than its default (which is tip_width = 0.25, tip_height = 0.25).
However the tip customization doesn't seem to be working.
Here is the code and the result:
from manim import *
class NumberLineComparison(Scene):
def construct(self):
l0 = NumberLine(
x_range=[-3,3],
include_tip=True
)
l1 = NumberLine(
x_range=[-3,3],
include_tip=True,
tip_width=0.1
).next_to(l0,DOWN)
l2 = NumberLine(
x_range=[-3,3],
include_tip=True,
tip_height=0.1
).next_to(l1,DOWN)
self.add(l0,l1,l2)
Resulting Image
The changes in tip_width and tip_height attributes don't seem to be active...
Is this a bug or are there any problems with the syntax?

Related

Is it possible to vectorize this calculation in numpy?

Can the following expression of numpy arrays be vectorized for speed-up?
k_lin1x = [2*k_lin[i]*k_lin[i+1]/(k_lin[i]+k_lin[i+1]) for i in range(len(k_lin)-1)]
Is it possible to vectorize this calculation in numpy?
x1 = k_lin
x2 = k_lin
s = len(k_lin)-1
np.roll(x2, -1) #do this do bring the column one position right
result1 = x2[:s]+x1[:s] #your divider. You add everything but the last element
result2 = x2[:s]*x1[:s] #your upper part
# in one line
result = 2*x2[:s]*x1[:s] / (x2[:s]+x1[:s])
You last column wont be added or taken into the calculations and you can do this by simply using np.roll to shift the columns. x2[0] = x1[1], x2[1] = x1[2].
This is barely a demo of how you should approach google numpy roll. Also instead of using s on x2 you can simply drop the last column since it's useless for the calculations.

Why isn't Python OpenCV HoughP Transform able to identify all the spaced lines?

When we have spaced lines on 1px. HoughP transform of python opencv doesn't mark all the points.
I used:
cv2.HoughLinesP(img,1,np.pi/180,400)
Theoretically it should be working fine be it dashed or non dashed. In this case it doesn't mark all the lines if they are on the same height.
HoughP Transfrom Sample Output
The Green Lines indicate the white lines that were identified.
I changed the parameters to this:
cv2.HoughLinesP(img,1,np.pi/180,10,10,10)
And got this output, as you can see the detection is still missing some parts. Its unclear how, for a straight line, a shorter line is marked but not a longer line.
*** After the method suggested!
After method suggested by Robert
Input Image: Input Image
Here is the code:
import numpy as np
import cv2
import time
img=cv2.imread("in.PNG")
img2=np.abs(img)
img=cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
ret,thresh1 = cv2.threshold(img,127,255,cv2.THRESH_BINARY)
lines = cv2.HoughLinesP(img,rho = 1,theta = 1*np.pi/180,threshold =
10,minLineLength = 10,maxLineGap = 10)
N = lines.shape[0]
print lines
for i in range(N):
x1 = lines[i][0][0]
y1 = lines[i][0][1]
x2 = lines[i][0][2]
y2 = lines[i][0][3]
cv2.line(img2,(x1,y1),(x2,y2),(0,255,0),1)
#cv2.imshow("Window",thresh1)
cv2.imwrite("out.PNG",img2)

How to optimize this image iteration in numpy? [duplicate]

This question already has answers here:
How to optimize this image iteration in numpy?
(2 answers)
Closed 5 years ago.
I'm using this code to detect green color in the image.
The problem is this iteration is really slow.
How to make it faster? If it is using numpy, How to do it in numpy way?
def convertGreen(rawimg):
width, height, channels = rawimg.shape
size = (w, h, channels) = (width, height, 1)
processedimg = np.zeros(size, np.uint8)
for wimg in range(0,width):
for himg in range(0,height):
blue = rawimg.item(wimg,himg,0)
green = rawimg.item(wimg,himg,1)
red = rawimg.item(wimg,himg,2)
exg = 2*green-red-blue
if(exg > 50):
processedimg.itemset((wimg,himg,0),exg)
return processedimg
I would go for something like this (untested):
def convertGreen(rawimg):
red, green, blue = rawimg[:,:,0], rawimg[:,:,1], rawimg[:,:,2]
exg = 2*green - red - blue
processedimg = exg.copy();
processedimg[processedimg < 50] = 0
return processedimg
The copy operation can actually be omitted, but I kept it to stay a bit more in line with the original code.
Note that in general programming questions are actually offtopic here, and more suitable for StackOverflow.

MS Chart Control Range Bar

I am trying to somehow replicate the range bar chart here.
I've found this reference but I don't fully grasp the code.
What I have is a series of task (sometimes accomplished in different periods).
let d = [("task1", DateTime.Parse("11/01/2014 08:30"), DateTime.Parse("12/01/2014 10:30"));
("task2", DateTime.Parse("15/01/2014 09:30"), DateTime.Parse("16/01/2014 10:30"));
("task3", DateTime.Parse("11/01/2014 08:30"), DateTime.Parse("16/01/2014 10:30"))]
let chart = d |> FSharp.Charting.Chart.RangeBar
chart.ShowChart()
I am struggling to understand the logic of the API.
I have also tried:
let chart = new Windows.Forms.DataVisualization.Charting.Chart(Dock = DockStyle.Fill)
let area = new ChartArea("Main")
chart.ChartAreas.Add(area)
let mainForm = new Form(Visible = true, TopMost = true, Width = 700, Height = 500)
mainForm.Controls.Add(chart)
let seriesColumns = new Series("NameOfTheSerie")
seriesColumns.ChartType <- SeriesChartType.RangeBar
type SupportToChart(serieVals: Series) =
member this.addPointXY(lbl, [<ParamArray>] yVals: Object[]) =
serieVals.Points.AddXY(lbl, yVals) |> ignore
let supporter = SupportToChart(seriesColumns)
supporter.addPointXY("AAA", DateTime.Parse("11/01/2014 08:30"), DateTime.Parse("12/01/2014 10:30") )
which results in
System.ArgumentOutOfRangeException: You can only set 1 Y values for
this data point.
Has something changed in the API since then?
I'm not entirely sure that F# Charting is currently powerful enough to be able to reconstruct the above chart. However, one of the problems seems to be that it treats dates as float values (for some reason) and incorrectly guesses the ranges. You can at least see the chart if you use:
Chart.RangeBar(d)
|> Chart.WithYAxis(Min=41650.0, Max=41660.0)
Please submit this as an issue on GitHub. If you want to dig deeper into how F# Charting works and help us get this fixed, that would be amazing :-)
The trick is initializing the Series with
let serie = new Series("Range", yValues)
where yValues defines the max number of "Y-values".

Rubymotion MapKit Path Overlay

Does anyone know of any code examples that display paths on a MKMapView using RubyMotion?
I've found some useful examples that display a point or pin but none that display a path.
Thanks
For the record I was able to draw a line on the map like this. Hopefully this is useful to someone as I could find no examples drawing lines on a map using RubyMotion:
arr = [CLLocationCoordinate2D.new(49.7414435, -123.08), CLLocationCoordinate2D.new(50.7414435, -123.0)]
ptr = Pointer.new(CLLocationCoordinate2D.type, arr.length)
ptr[0] = arr[0]
ptr[1] = arr[1]
pl = MKPolyline.polylineWithCoordinates(ptr, count:2)
view.addOverlay(pl)
With the help of this discussion:
https://groups.google.com/forum/?fromgroups=#!topic/rubymotion/F5CH780lu7c
To expand upon this (which was very helpful), you also need to create a viewForOverlay method, like so:
def mapView(map_view, viewForOverlay:overlay)
if overlay.class == MKPolyline
overlayView = MKPolylineView.alloc.initWithPolyline(overlay)
overlayView.strokeColor = UIColor.systemRedColor
overlayView.lineWidth = 2
overlayView
end
end

Resources