How do I fix OpenCV function "contourArea" error? - contour

I am doing an assignment and this error pops up
File "/mnt/c/Users/nasos/Desktop/Pierce/Racecar/racecar-racecar-pierce/labs/lab2/../../library/racecar_utils.py", line 594, in get_contour_area
return cv.contourArea(contour)
cv2.error: OpenCV(4.5.5) /io/opencv/modules/imgproc/src/shapedescr.cpp:315: error: (-215:Assertion failed) npoints >= 0 && (depth == CV_32F || depth == CV_32S) in function 'contourArea'
What do I do?

Related

Problems with rqpd - CRE method

I've been trying to run a quantile regression for panel data in R, using the 'rqpd' package and it works normally for PFE method (fixed effects). However, when I run the CRE method, it fails. Below are the codes I am using and the messages the program returns. Could someone give me a help, please?
> cre.form <- lnemp ~ lngt + lneduc + lndesp + lngdp | ID | lngt + lneduc + lndesp + lngdp
> crem.fit <- rqpd(cre.form, panel("cre"), data=Panel12)
Error messages:
Error in switch(ierr, "insufficient storage (work space) when calling extract\n", :
EXPR must be a length 1 vector
In addition: Warning messages:
1: In .local(x, ...) : singularity problem
2: In .local(x, ...) : singularity problem
3: In .local(x, ...) : singularity problem
4: In .local(x, ...) : singularity problem
5: In (fit$ierr != 0) && (fit$it < 5) :
'length(x) = 3 > 1' in coercion to 'logical(1)'
6: In (fit$ierr != 0) && (fit$it < 5) :
'length(x) = 3 > 1' in coercion to 'logical(1)'

when I run the code below,I am getting an error as "index 0 is out of bounds for axis 0 with size 0"

This is my code below
def recomend_book(book_name):
b_id = np.where(books_rating_pivot.index == book_name)[0][0]
_, recommendations = model.kneighbors(books_rating_pivot.iloc[b_id,:].values.reshape(1,-1))
for i in range(len(recommendations)):
if i == 0:
print(f"For book \"{book_name}\" is recommended")
if not i:
print(books_rating_pivot.index[recommendations[i]])
recomend_book('Harry')

go error % not allowed

I have written a program for Mumax with a go syntax but I don't understant my error. Here the script where the error appears :
n:=0
Dtr0:=5*1e-12
Dtd0 :=300*1e-12
Dtf0:=5*1e-12
Dtz0:=20000*1e-12
tr0:=Dtr0
td0:=Dtd0+tr0
tf0:=Dtf0+td0
tz0:=Dtz0+tf0
TT:=tz0
n=t/TT
tr:=tr0+(n*TT)
td:=td0+(n*TT)
tf:=tf0+(n*TT)
tz:=tz0+(n*TT)
if (n % 2 == 0) {
if (n<1 && t<tr) {
a:=(t/tr)
} else if (n>=1 && t>=tz0+((n-1)*TT) && t<tr) {
a:=1/(tr-(tz0+((n-1)*TT)))*(t-(tz0+((n-1)*TT)))
} else if (t>=tr && t<=td) {
a:=1
} else if (t>td && t<=tf) {
a:=(-1/(tf-td))*(t-td)+1
} else if (t>tf && t<tz) {
a:=0
}
}
if (int(n)%2==1) {
if (n<1 && t<tr) {
a:=-(t/tr)
} else if (n>=1.0 && t>=tz0+((n-1)*TT) && t<tr) {
a:=-(1/(tr-(tz0+((n-1)*TT)))*(t-(tz0+((n-1)*TT))))
} else if (t>=tr && t<=td) {
a:=-1
} else if (t>td && t<=tf) {
a:=-((-1/(tf-td))*(t-td)+1)
} else if (t>tf && t<tz) {
a:=0
}
}
And the error message is : line 37: if (n % 2 == 0) {: not allowed: %
Thank's a lot
There are two problems here:
n must be a float because TT must be a float, because that's ultimately a function of two floats. This conflicts with the n := 0 default int definition at the top.
the modulus operator on floats is undefined (see this playground for what happens when you try).
This means you have a very weird Go implementation or we're not seeing everything.
In any case, either you have to either coerce n to an int (as you do in your second if) or use math.Mod somehow.

Compile errors with Fortran90

All, I've been fighting these errors for hours, here's my code:
program hello
implicit none
integer :: k, n, iterator
integer, dimension(18) :: objectArray
call SetVariablesFromFile()
do iterator = 1, 18
write(*,*) objectArray(iterator)
end do
contains
subroutine SetVariablesFromFile()
IMPLICIT NONE
integer :: status, ierror, i, x
open(UNIT = 1, FILE = 'input.txt', &
ACTION = 'READ',STATUS = 'old', IOSTAT = ierror)
if(ierror /= 0) THEN
write(*, *) "Failed to open input.txt!"
stop
end if
do i = 1, 18
objectArray(i) = read(1, *, IOSTAT = status) x
if (status > 0) then
write(*,*) "Error reading input file"
exit
else if (status < 0) then
write(*,*) "EOF"
exit
end if
end do
close(1)
END subroutine SetVariablesFromFile
end program hello
I'm getting compile errors:
make: * [hello.o] Error1
Syntax error in argument list at (1)
I read online that the latter error could be due to a long line of code exceeding 132 characters, which doesn't appear to be the problem.I have no where to begin on the first error... any help would be much appreciated!
This,
objectArray(i) = read(1, *, IOSTAT = status) x
is not valid Fortran. You need to write it as,
read(1,*,iostat=status) objectArray(i)
Setting it in this correct form, I received no compiler errors with ifort 12.1, nor with gfortran 4.4.3

LINQ to Entities grouped logical operations in Where

I'm trying to execute the following linq query and it seems to be ignoring order of operations. (Parentheses first)
var result = _repo.Transactions.Where(t =>
t.DateEntered > EntityFunctions.AddDays(DateTime.Now, -7)
&& ( t.TranDesc != "BALANCE FORWARD" && t.Withdrawl == 0 && t.Deposit == 0 ) );
Here's the where clause that generates:
WHERE ([Extent1].[dateentered] > (DATEADD (day, -7, SysDateTime())))
AND (N'BALANCE FORWARD' <> [Extent1].[TranDesc])
AND (cast(0 as decimal(18)) = [Extent1].[Withdrawl])
AND (cast(0 as decimal(18)) = [Extent1].[Deposit])
Any ideas what I'm doing wrong?
EDIT:
This is actually what I wanted and it solved my problem. Just didn't think it all the way though. Thanks.
var result = _repo.Transactions.Where(t =>
t.dateentered > EntityFunctions.AddDays(DateTime.Now, -7)
&& ((t.TranDesc == "BALANCE FORWARD" && (t.Withdrawl != 0 || t.Deposit != 0))
|| (t.TranDesc != "BALANCE FORWARD")));
There is no difference between a && (b && c && d) and a && b && c && d, and that's why parentheses within generated SQL are not exactly the same as in your LINQ query. But at the end there is no difference between these queries.

Resources