I'm working on Mat in OpenCV. However, I need to manually calculate the Mat by myself. Is there is a way of accessing Mat likes 2D array?
const myMat = cv.matFromArray(cv, 3, 3, cv.CV_64F, [
[1, 2, 3],
[4, 5, 6],
[7, 8, 9],
])
const newMat = someProcessThatReturnMat(myMat)
/* OpenCV in JS cannot access Mat like this */
const result = someProcess(newMat[1][2], newMat[2][0])
Thank you in advance
Updated: The problem is cv.matFromArray cannot convert 2D array to Mat. You have to use it as 1D array. That's why it never return the correct values. For example:
const myMat = cv.matFromArray(3, 3, cv.CV_64F, [1,2,3,4,5,6,7,8,9])
And then, you can access the value
const value = myMat.doubleAt(1, 2) // row 1, col 2
You need to use the doubleAt(y,x) method.
It's double because the mat's content is CV_64F, not because you want doubles.
You can also use .data64F to access a flat Float64Array of the Mat's data.
OpenCV.js is... rough. It originated from someone's Google Summer of Code and hasn't received significant care since. Documentation amounts to some tutorials; API docs seem to be missing entirely. The "Mat" interface emulated the at() method from C++, badly, instead of looking at numpy (python) or making this access feel "native" to javascript. Overloading the [] operator is possible using a Proxy but that was not implemented.
Here's an example: https://docs.opencv.org/4.x/de/d06/tutorial_js_basic_ops.html
Feel free to browse OpenCV's issues and maybe suggest some improvements.
Okay so...I'm in the process of creating a python client for a coding game I play. This game is originally created in javascript and employs a json object of game data found at https://adventure.land/data.js. Within this data, each map has a list of doors, and each door within this list is a list of attributes. For example:
"doors":[[-965,-176,24,30,"woffice",0,1],[536,1665,64,32,"tunnel",0,2],[168,-149,32,40,"bank",0,3],[160,1370,24,32,"cave",0,4],[232,384,24,30,"arena",0,6],[-472,131,24,30,"tavern",0,8],[616,610,32,40,"mansion",0,10],[1936,-23,24,24,"level1",1,11],[169,-404,24,40,"hut",0,14],[1600,-547,60,40,"halloween",4,15],[312,-335,32,32,"mtunnel",0,16],[967,-584,32,32,"mtunnel",1,17],[1472,-434,32,32,"mtunnel",2,18]]
However, when sent from python to julia, it suddenly becomes:
"doors":[-965,-176,24,30,"woffice",0,1,536,1665,64,32,"tunnel",0,2,168,-149,32,40,"bank",0,3,160,1370,24,32,"cave",0,4,232,384,24,30,"arena",0,6,-472,131,24,30,"tavern",0,8,616,610,32,40,"mansion",0,10,1936,-23,24,24,"level1",1,11,169,-404,24,40,"hut",0,14,1600,-547,60,40,"halloween",4,15,312,-335,32,32,"mtunnel",0,16,967,-584,32,32,"mtunnel",1,17,1472,-434,32,32,"mtunnel",2,18]
Is there some way to prevent this from happening? If not, is there a possible workaround? Because my for door in doors code in python won't exactly have the same effect when given a direct translation to julia considering the random list flattening.
Edit: I've been asked to provide "minimum reproducible code" but I'm not too sure what the minimum is so I'll just say...
create a some function in julia that prints a dictionary
function printDict(d)
println(d)
end
create a dictionary in python that contains a nested list
nestedlistdict = {"data": [[0,1,2,3],[4,5,6,7]]}
call the printDict function from python while sending the nestedlistdict variable as an argument
from julia import Main
Main.include("path/to/your/julia/file")
Main.file.printDict(nestedlistdict)
result should be:
Dict{Any, Any}("data" => [[0, 1, 2, 3], [4, 5, 6, 7]])but instead my result is Dict{Any, Any}("data" => [0 1 2 3; 4 5 6 7])
Edit2: upon further testing, it seems to be having the issue because it converts a nested list into a Matrix object instead of a nested Vector object.
Julia uses the same interpretation of list of lists as numpy:
>>> np.array([[1,2,3],[4,5,6]])
array([[1, 2, 3],
[4, 5, 6]])
or in Julia:
julia> using PyCall
julia> py"[[1,2,3],[4,5,6]]"
2×3 Matrix{Int64}:
1 2 3
4 5 6
If you want to have an actual vector of vectors you need to do the same way as you need to do a vector of numpy arrays.
Python version:
>>> [np.array([1,2,3]),np.array([1,2,3])]
[np.array([1, 2, 3]), np.array([1, 2, 3])]
Julia version (this is what you are actually asking for):
julia> np = pyimport("numpy");
julia> py"[$np.array([1, 2, 3]), $np.array([1, 2, 3])]"
2-element Vector{Vector{Int32}}:
[1, 2, 3]
[1, 2, 3]
Another, perhaps simpler option could be packing that all to a tuple:
julia> py"tuple([[1,2,3],[4,5,6]])"
([1, 2, 3], [4, 5, 6])
I'm looking for a way get a console output from Google Chrome into my python program. I have a script coded in JS that finishes in around 1 second, but my python implementation (exactly same logic, etc, the only diff is that it's in Python and not JS) takes about 15 seconds to run. Therefore I'm looking for a way to get the printout in Chrome console to my python program.
This is the current way I'm doing it:
Python program uses pyautogui to click and does what it needs to do inside to trigger the function running in JS.
JS completes the function in 1s and prints to console, something like:
(22) [6, 4, 4, 6, 0, 0, 2, 4, 4, 6, 4, 2, 4, 4, 6, 0, 0, 2, 4, 4, 6, 0]
I need to get that into my python program so it can does the rest of the stuff..
I need a javascript (HTML4/5) based library to draw a line chart that has irregular data (and one or more series).
Here is an example:
x-axis = [1, 2, 3, 4, 5, 6, 7, 8]
series1 (y-axis) = [6, 10, null, 8, null, 7, 6, 4]
series2 (y-axis) = [null, 8, 8, null, 1, 3, 5, 4]
In this chart the nulls are not taken in consideration; are in some way "skipped" and the line goes directly into the next value. Of course i want to highlight the points to know if a point is or isn't there at that x value.
There are some of this charts with irregular data based on time series (like this highcharts.com/demo/spline-irregular-time) but i need that defining my own (regular) x-axis.
What do you suggest?
Highcharts can accept irregular data without using times.
Basically, you take the example that you posted, and remove the type: 'datetime' option, and specify numbers instead of dates in the series.
I have posted an example here: http://jsfiddle.net/TRLhc/