usage:
OpenCV 4.5.3-dev
I followed this example: https://github.com/opencv/opencv/blob/master/samples/dnn/scene_text_spotting.cpp
It is use:
for the detection model: DB_TD500_resnet50.onnx
for the recognition model : crnn_cs.onnx
for the vocabulary: alphabet_94.txt
the decode type is set to: "CTC-prefix-beam-search"
These settings received the following error:
OpenCV(4.5.3-dev) C:\DevTools\opencv\modules\dnn\src\model.cpp:745: error: (-2:Unspecified error) in function 'class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > __cdecl cv::dnn::TextRecognitionModel_Impl::ctcPrefixBeamSearchDecode(const class cv::Mat &)'
> (expected: 'prediction.size[2] == (int)vocabulary.size() + 1'), where
> 'prediction.size[2]' is 96
> must be equal to
> '(int)vocabulary.size() + 1' is 95
Add one empty line at the end of the vocabulary or push_back one more item in the vocabulary vector.
I don't know if is only a workaround or a real solution...
I have this formula:
=query(A6:D848,"Select * where D LIKE'"&AC1&"' AND A <> 'Grand Total'",0)
Where AC1 has a value of 2 in it.
The above works a treat, but when I try to change the LIKE to a >, I get an error.
=query(A6:D848,"Select * where D >'"&AC1&"' AND A <> 'Grand Total'",0)
I'm assuming that it's because referencing a cell value gives back a string value an not an number, but I can't figure out how to get it to change to an number and make the query work.
=query(A6:D848,"Select * where D > "&AC1&" AND A <> 'Grand Total'",0)
You received the error, because you had several quotes there.
'"&AC1&"' = ' + " + &AC1& + " + '
You needed to remove the single quotes, because those were required for LIKE and not needed for >.
I'm writing a grammar that includes exactly three alphabetic characters. Here's my code:
local l = require "lpeg"
l.locale(l)
local date = l.digit^1 * l.P'/' * l.digit^1 * l.P'/' * l.digit^1
local time = l.digit^1 * l.P':' * l.digit^1 * l.P':' * l.digit^1 * l.P':' * l.digit^1
local timezone = l.alpha^3
local stamp = l.P'[' * date * l.P' ' * time * l.P' ' * timezone * l.P']'
grammar = l.C(stamp)
The input I'm matching against is this:
[4/23/15 4:49:49:371 CDT]
How do I get the expression to match only three alphabetic characters in the timezone? The way this code works now is it will match three or more alphabetic characters.
Weird! Does this work?
local timezone = l.alpha*2
It seems to, but I can't find that syntax referenced anywhere here:
http://www.inf.puc-rio.br/~roberto/lpeg/lpeg.html
l.alpha*2 is l.alpha * l.P(2).
So no, that matches [a-z]...
See the output from lpeg.print(timezone) to confirm that. (Note my use of ll for the locale data. Putting it in the same table loses the original print debugging function.)
> l=require"lpeg"
> ll=lpeg.locale()
> p=ll.alpha*2
> l.print(p)
[]
00: set [(41-5a)(61-7a)]-> FAIL
05: any * 2-> FAIL
06: end
> =p.match("099")
nil
> =p.match("EST")
4
> =p.match("E99")
4
The pattern you want is:
> function patcount(pat, min, max)
>> return -pat^(max + 1) * pat^min
>> end
> p=patcount(ll.alpha, 3, 3)
> lpeg.print(p)
[]
00: set [(41-5a)(61-7a)]-> 27
05: choice -> 27 (1)
06: set [(41-5a)(61-7a)]-> FAIL
11: set [(41-5a)(61-7a)]-> FAIL
16: set [(41-5a)(61-7a)]-> FAIL
21: span [(41-5a)(61-7a)]
26: failtwice
27: set [(41-5a)(61-7a)]-> FAIL
32: set [(41-5a)(61-7a)]-> FAIL
37: set [(41-5a)(61-7a)]-> FAIL
42: span [(41-5a)(61-7a)]
47: end
> =p:match("EST")
4
> return p:match("ES")
nil
> return p:match("ESTT")
nil
> return p:match("099")
nil
> return p:match("E99")
nil
The relevant documentation bit is -patt.
As to the l.alpha*2 syntax that's explained by this quote from the manual.
All operations that expect a pattern as an argument may receive also strings, tables, numbers, booleans, or functions, which are translated to patterns according to the rules of function lpeg.P.
Which is to say that the operators convert non-patterns to patterns when one of the operands is a pattern already.
There's also the 'Match a fixed number of repetitions of a pattern' section (and the link) on the LpegRecipes lua-users.org wiki page. (But I haven't looked over that implementation at all and it looks more complicated than mine above.)
I am writing code in gfortran to separate a variable time stamp into its separate parts of year, month, and day. I have written this code so the user can input what the time stamp format will be (ie. YEAR/MON/DAY, DAY/MON/YEAR, etc). This creates a total of 6 possible combinations. I have written code that attempts to deal with this, but I believe it to be ugly and poorly done.
My current code uses a slew of 'if' and 'goto' statements. The user provides 'tsfo', the time stamp format. 'ts' is a character array containing the time stamp data (as many as 100,000 time stamps). 'tsdelim' is the delimiter between the year, month, and day. I must loop from 'frd' (the first time stamp) to 'nlines' (the last time stamp).
Here is the relevant code.
* Choose which case to go to.
first = INDEX(tsfo,tsdelim)
second = INDEX(tsfo(first+1:),tsdelim) + first
if (INDEX(tsfo(1:first-1),'YYYY') .ne. 0) THEN
if (INDEX(tsfo(first+1:second-1),'MM') .ne. 0) THEN
goto 1001
else
goto 1002
end if
else if (INDEX(tsfo(1:first-1),'MM') .ne. 0) THEN
if (INDEX(tsfo(first+1:second-1),'DD') .ne. 0) THEN
goto 1003
else
goto 1004
end if
else if (INDEX(tsfo(1:first-1),'DD') .ne. 0) THEN
if (INDEX(tsfo(first+1:second-1),'MM') .ne. 0) THEN
goto 1005
else
goto 1006
end if
end if
first = 0
second = 0
* Obtain the Julian Day number of each data entry.
* Acquire the year, month, and day of the time stamp.
* Find 'first' and 'second' and act accordingly.
* Case 1: YYYY/MM/DD
1001 do i = frd,nlines
first = INDEX(ts(i),tsdelim)
second = INDEX(ts(i)(first+1:),tsdelim) + first
read (ts(i)(1:first-1), '(i4)') Y
read (ts(i)(first+1:second-1), '(i2)') M
read (ts(i)(second+1:second+2), '(i2)') D
* Calculate the Julian Day number using a function.
temp1(i) = JLDYNUM(Y,M,D)
end do
goto 1200
* Case 2: YYYY/DD/MM
1002 do i = frd,nlines
first = INDEX(ts(i),tsdelim)
second = INDEX(ts(i)(first+1:),tsdelim) + first
read (ts(i)(1:first-1), '(i4)') Y
read (ts(i)(second+1:second+2), '(i2)') M
read (ts(i)(first+1:second-1), '(i2)') D
* Calculate the Julian Day number using a function.
temp1(i) = JLDYNUM(Y,M,D)
end do
goto 1200
* Onto the next part of the code
1200 blah blah blah
I believe this code will work, but I do not think it is a very good method. Is there a better way to go about this?
It is important to note that the indices 'first' and 'second' must be calculated for each time stamp as the month and day can both be represented by 1 or 2 integers. The year is always represented by 4.
With only six permutations to handle I would just build a look-up table with the whole tsfo string as the key and the positions of year, month and day (1st, 2nd or 3rd) as the values. Any unsupported formats should produce an error, which I haven't coded below. When subsequently you loop though your ts list and split an item you know which positions to cast to the year, month and day integer variables:
PROGRAM timestamp
IMPLICIT NONE
CHARACTER(len=10) :: ts1(3) = ["2000/3/4 ","2000/25/12","2000/31/07"]
CHARACTER(len=10) :: ts2(3) = ["3/4/2000 ","25/12/2000","31/07/2000"]
CALL parse("YYYY/DD/MM",ts1)
print*
CALL parse("DD/MM/YYYY",ts2)
CONTAINS
SUBROUTINE parse(tsfo,ts)
IMPLICIT NONE
CHARACTER(len=*),INTENT(in) :: tsfo, ts(:)
TYPE sti
CHARACTER(len=10) :: stamp = "1234567890"
INTEGER :: iy = -1, im = -1, id = -1
END TYPE sti
TYPE(sti),PARAMETER :: stamps(6) = [sti("YYYY/MM/DD",1,2,3), sti("YYYY/DD/MM",1,3,2),&
sti("MM/DD/YYYY",2,3,1), sti("DD/MM/YYYY",3,2,1),&
sti("MM/YYYY/DD",2,1,3), sti("DD/YYYY/MM",3,1,2)]
TYPE(sti) :: thisTsfo
INTEGER :: k, k1, k2
INTEGER :: y, m, d
CHARACTER(len=10) :: cc(3)
DO k=1,SIZE(stamps)
IF(TRIM(tsfo) == stamps(k)%stamp) THEN
thisTsfo = stamps(k)
EXIT
ENDIF
ENDDO
print*,thisTsfo
DO k=1,SIZE(ts)
k1 = INDEX(ts(k),"/")
k2 = INDEX(ts(k),"/",BACK=.TRUE.)
cc(1) = ts(k)(:k1-1)
cc(2) = ts(k)(k1+1:k2-1)
cc(3) = ts(k)(k2+1:)
READ(cc(thisTsfo%iy),'(i4)') y
READ(cc(thisTsfo%im),'(i2)') m
READ(cc(thisTsfo%id),'(i2)') d
PRINT*,ts(k),y,m,d
ENDDO
END SUBROUTINE parse
END PROGRAM timestamp
I would encode the different cases in another way, like this:
module foo
implicit none
private
public encode_datecode
contains
integer function encode_datecode(datestr, sep)
character(len=*), intent(in) :: datestr, sep
integer :: first, second
character(len=1) :: c1, c2, c3
first = index(datestr, sep)
second = index(datestr(first+1:), sep) + first
c1 = datestr(1:1)
c2 = datestr(first+1:first+1)
c3 = datestr(second+1:second+1)
foo = num(c1) + 3*num(c2) + 9*num(c3)
end function encode_datecode
integer function num(c)
character(len=1) :: c
if (c == 'Y') then
num = 0
else if (c == 'M') then
num = 1
else if (c == 'D') then
num = 2
else
stop "Illegal character"
end if
end function num
end module foo
and then handle the legal cases (21, 15, 19, 7, 11, 5) in a SELECT statement.
This takes advantage of the fact that there won't be a 'YDDY/MY/YM' format.
If you prefer better binary or decimal readability, you can also multiply by four or by 10 instead of 3.
I trying to write some condition to pull out objects from database:
Page.where(published: true).where("`published_at` <= current_date()").where("`publication_end` IS NULL OR `publication_end` > current_date()")
When i enter it in the rails console i have the following error:
SELECT "pages".* FROM "pages" WHERE "pages"."published" = 't' AND (`published_at` <= current_date()) AND (`publication_end` IS NULL OR `publication_end` > current_date())
PG::SyntaxError: ERROR: syntax error at or near "("
LINE 1: ...blished" = 't' AND (`published_at` <= current_date()) AND (`...
^
: SELECT "pages".* FROM "pages" WHERE "pages"."published" = 't' AND (`published_at` <= current_date()) AND (`publication_end` IS NULL OR `publication_end` > current_date())
ActiveRecord::StatementInvalid: PG::SyntaxError: ERROR: syntax error at or near "("
LINE 1: ...blished" = 't' AND (`published_at` <= current_date()) AND (`...
^
: SELECT "pages".* FROM "pages" WHERE "pages"."published" = 't' AND (`published_at` <= current_date()) AND (`publication_end` IS NULL OR `publication_end` > current_date())
I,m Using Postgresql
Please help.
Remove the parentheses:
# select current_date();
ERROR: syntax error at or near "("
LINE 1: select current_date();
# select current_date;
date
------------
2014-02-19
(1 row)
i write:
Page.where(published: true).where("published_at <= current_date").where("publication_end IS NULL OR publication_end > current_date")
and now i ok
Thanks :)