Error while detecting cars on video TypeError: integer argument expected, got float - trackback

I am new to Python, working on vehicles detection, and I am getting this error.
I do not know why I am getting this error and what the solution is to solve the problem.
I am getting an error on the following line.
I have tried the solution, and I found but have not solved the problem:
frame = cv2.resize(frame,(frameWidth/2, frameHeight/2))
frameHeight, frameWidth, fdepth = frame.shape

Try this:
frame = cv2.resize(frame,(int(frameWidth/2), int(frameHeight/2)))
frameHeight, frameWidth, fdepth = frame.shape
When you divide odd numbers by 2 you end up creating a floating point value.

Related

How to use exec() to construct multiple for-loops

I'm trying to processing batchs with variable batch sizes. To do so, I attempted to construct multiple for-loops using exec(). However, it is seemed not supported by Python, as an error is reported: "unexpected indent".
The code is shown as follows, and the error occurs at the last line, which seems that the Python interpreter couldn't recognize the for-loop nested in function exec():
for b in range(num_loader + 1):
exec("for i, batch_data in enumerate(data_train_loader%s):"%b)
batch_data = batch_data.to(device)
I solve the recognition problem through this way:
for b in range(num_loader + 1):
exec("data_train_loader = data_train_loader%s"%b)
for i, batch_data in enumerate(data_train_loader):
batch_data = batch_data.to(device)
However, I got an new error which hints that data_train_loader is not defined. I check it through pdb, which show it did has a definition. Could anybody help me with that?
error report

Getting an error when calculating Z score

I am trying to find the outliers in my dataset and remove them. So I did the following:
z_scores = stats.zscore(dataset_sex)
abs_z_scores = np.abs(z_scores)
filtered_entries = (abs_z_scores < 3).all(axis=1)
new_df = dataset_sex[filtered_entries]
new_df.head()
but I got this error:
TypeError: unsupported operand type(s) for /: 'str' and 'int'
The error seems to generate from the first line of code (z_scores = stats.zscore(dataset_sex)). I don't understand why. How can I fix this?
This comes from some of your data in the columns being strings (in python terms 'str').
When it comes from working out the z-score, it will have to divide the mean with a standard deviation. One of the columns is a string like 'M' or 'F' for sex, or strings like '1,232.23' not converted to floats, and z-scoring does not work for that.
My first suggestion is to check that they are all numbers.
df.dtypes
will show you what types they are and then convert them to numeric.
Post a little of the data (a couple of rows) and we can help you.

I dont understand why i get this error in my code. ValueError: operands could not be broadcast together with shapes (24,) (26,)

I keep getting this error im not entirely sure what it means. i just started coding about 2 weeks ago. All i want to do is change my velocity graph into an acceleration graph.
i've tried changing the times function from times[1:] to times[2:]. i still get the same error message.
print(x)
print(y)
plt.scatter(times, y/np.max(np.abs(y)))
changex = np.diff(x) #takes difference in x plot points
changey = np.diff(y) #takes difference in y plot points
dt = np.diff(times)
plt.plot(times[1:],(changey/dt)/np.max(changey/dt))
plt.show()
velocity = (changey/dt)/np.max(changey/dt)
print(velocity)
changev = np.diff(velocity)
plt.plot(times[1:],(changev/dt)/np.max(changev/dt))
plt.show()
The line I believe to be giving me this issue is:
plt.plot(times[1:],(changev/dt)/np.max(changev/dt))

while find Max of two pandas element of current and previous getting error 'list' object has no attribute 'max'

Sadly I get this error when I try to do max() tried with multiple [] () combination and the error keeps on coming .
Looks like this is minor issue and easily solvable. Before posting it here referred some of the existing posts still could not figure out the way.
Any help much appreciated. The code fails after if is evaluated (last line)
for i in range(1, len(df)):
if(df[source].iat[i] > df[trail].iat[i - 1]) and (df[source].iat[i-1] > df[trail].iat[i-1]):
df[trail].iat[i] = [df[trail].iat[i-1],df[source].iat[i]- df['nLoss'].iat[i]].max()
error :'list' object has no attribute 'max'
Thanks for your support in advance.
Need function max function working with iterables in python:
for i in range(1, len(df)):
if(df[source].iat[i] > df[trail].iat[i - 1]) and (df[source].iat[i-1] > df[trail].iat[i-1]):
df[trail].iat[i] = max([df[trail].iat[i-1],df[source].iat[i]- df['nLoss'].iat[i]])

Error in retainedges[dat$seg] : invalid subscript type 'list'

I am conducting linearK function for the observed point pattern on a linear network and I get the following error
Error in retainedges[dat$seg] : invalid subscript type 'list'
I do not understand what it means and how should I correct it.
On the traceback call, I get the following information
> traceback()
4: thinNetwork(x, retainvertices = subi)
3: countends(L, X[-j], D[-j, j], toler = toler)
2: linearKengine(X, r = r, ..., denom = denom, correction = correction,
ratio = ratio)
1: linearK(sl2)
Could someone help me on what this error means and how I can correct it.
Thank you.
Your network is a bit problematic since it is disconnected. It has one very big component with 3755 vertices and 5593 lines and then 5 small components with only 2 or 3 vertices and 1 or 2 lines that are not connected to anything else. In your example you have only two points in this big network (both occurring in the big component as far as I can tell). We might be able to handle this in future versions of spatstat, but for now I suggest you simply discard the small empty components. Then I think linearK works as expected for your example (although I doubt you find interesting information from a pattern of 2 points!).
To identify connected components of a linear network use connected.linnet with argument what = "components" then you get a list of connected components and you can use the big connected component to define a new lpp on a connected linnet. With your example you could do something like (noting that component number 1 is the main component):
comp <- connected(as.linnet(sl2), what = "comp")
sl2new <- lpp(as.ppp(sl2), comp[[1]])

Resources