OpenCV cannot read manually edited YAML parameters - opencv

I manually add a custom matrix to a YAML file for openCV parameters, the problem is it cannot read the matrix and so OpenCV returns none-type. I do not know what is happening here as I tried editing both in notepad and visual studio code.
%YAML:1.0
---
test_matrix: !!opencv-matrix
rows: 2
cols: 2
dt: i
data: [ 1, 1, 1, 1 ]

Related

highchartr: Synchronize point and line colors and legend

I'm using the highchartr package to create an interactive chart.
My chart has lines on it corresponding to different series. In addition, I would like to have shapes at certain points on the lines.
Its very easy to get the points in the right place. However, I would like to map the point color to the line it is associated with. And when the user clicks on the legend entry for the line, I'd like the associated points to be toggled as well.
The code looks like this:
highchart() %>%
hc_add_series(
type="line",
marker=list(enabled=F),
data=input_data,
mapping=hcaes(x=x, y=y, group=series_name)
) %>%
hc_add_series(
type="point",
data=input_data %>% filter(! is.na(marker)),
mapping=hcaes(x=x, y=y, color=series_name, fill=series_name, group=series_name, shape=marker)
)
The result gets the points in the right place. But the point color is on a different color mapping from the lines. Clicking on the entry for the line in the legend toggles only the line - the points show up as separate entries by series_name.
What
What can I do so:
- The points and lines share the same color mapping
- The points and lines can be toggled together by clicking on the line in the legend
- The points show up separately in the legend based on their shape rather than their color?
Thanks!
Generally, it can be achieved in at least few different ways. It all depends on your data which you haven't provided (I created a sample data).
Additionally, I will provide all the examples in jsFiddle (JavaScript) because it is faster to explain something that way with a quick online example.
The final answer will contain R code (maybe with some custom JavaScript if needed, but all will be reproducible in R.
First of all, your assumption that you need a separate series is wrong and causes problems. If you want markers on your line with the same color and you want to toggle them together on legend click, then you don't need separate series - one series with markers enabled on some points is enough, see this example: https://jsfiddle.net/BlackLabel/s24rk9x7/
In this case, the R data needs to be defined properly.
If you don't want to keep it simple as described above, you can keep lines and markers as separate series as in your original question.
In this case, you can use series.linkedTo property to connect your "point" series to line series (BTW in Highcharts there is no something like "point" series type, it is "scatter" series type. Another reason why your code is wrong and is not working and you got unvoted), but there is a problem with it in Highcharter - doesn't work, seems like a bug and should be reported on Highcharter GitHub repo.
This is a JavaScript version which works fine: https://jsfiddle.net/BlackLabel/3mtdfqLo/
In this example, if you want to keep markers and line series in the same color, you can define colors manually or you can write some custom code (like I did) that will change the color for you automatically.
And this is the same R version which should work, but is not:
library(highcharter)
highchart() %>%
hc_add_series(
data=list(4, 3, 5, 6, 2, 3)
) %>%
hc_add_series(
data=list(14, 13, 15, 16, 12, 13),
id="first"
) %>%
hc_add_series(
data=list(10, 8, 6, 2, 5, 12),
id="second"
) %>%
hc_add_series(
type="scatter",
linkedTo="first",
data=list(list(1, 3), list(2, 5))
) %>%
hc_add_series(
type="scatter",
linkedTo="second",
data=list(list(1, 13), list(2, 15), list(3, 16))
) %>%
hc_plotOptions(
line = list(marker=list(enabled=F))
)
There is probably something wrong with hc_add_series function.
As a workaround, you can write it all as a custom JavaScript code, which (again) works fine:
library(highcharter)
highchart() %>%
hc_plotOptions(
line = list(marker=list(enabled=F))
) %>%
hc_chart(
events = list(load = JS("function() {
this.addSeries({
data: [4, 3, 5, 6, 2, 3],
id: 'first'
});
this.addSeries({
data: [14, 13, 15, 16, 12, 13],
id: 'second'
});
this.addSeries({
data: [10, 8, 6, 2, 5, 12]
});
this.addSeries({
type: 'scatter',
linkedTo: 'first',
data: [[1, 3], [2, 5]]
});
this.addSeries({
type: 'scatter',
linkedTo: 'second',
data: [[1, 13], [2, 15], [3, 16]]
});
}")))
Of course, last examples don't contain functionality that changes colors - you can copy it from the jsFiddle above.

How to turn a frequency domain graph to time domain graph

I wanted to convert the graph in the top red box for the frequency domain to the graph in the bottom red box for the time domain. What should I do?
Assuming you are using python, you can use the scipy library irfft function as explained here to get back the time domain signal.
Example:
from scipy.fftpack import fft,irfft,rfft
data = [0, 1, 2, 3, 4, 5]
fft = rfft(data)
print("FFT : " , fft)
original_data = irfft(fft)
print("Original : " , original_data)
Output :
FFT : [15. -3. 5.2 -3. 1.73 -3. ]
Original : [0. 1. 2. 3. 4. 5.]

Correct way to split data to batches for Keras stateful RNNs

As the documentation states
the last state for each sample at index i in a batch will be used as
initial state for the sample of index i in the following batch
does it mean that to split data to batches I need to do it the following way
e.g. let's assume that I am training a stateful RNN to predict the next integer in range(0, 5) given the previous one
# batch_size = 3
# 0, 1, 2 etc in x are samples (timesteps and features omitted for brevity of the example)
x = [0, 1, 2, 3, 4]
y = [1, 2, 3, 4, 5]
batches_x = [[0, 1, 2], [1, 2, 3], [2, 3, 4]]
batches_y = [[1, 2, 3], [2, 3, 4], [3, 4, 5]]
then the state after learning on x[0, 0] will be initial state for x[1, 0]
and x[0, 1] for x[1, 1] (0 for 1 and 1 for 2 etc)?
Is it the right way to do it?
Based on this answer, for which I performed some tests.
Stateful=False:
Normally (stateful=False), you have one batch with many sequences:
batch_x = [
[[0],[1],[2],[3],[4],[5]],
[[1],[2],[3],[4],[5],[6]],
[[2],[3],[4],[5],[6],[7]],
[[3],[4],[5],[6],[7],[8]]
]
The shape is (4,6,1). This means that you have:
1 batch
4 individual sequences = this is batch size and it can vary
6 steps per sequence
1 feature per step
Every time you train, either if you repeat this batch or if you pass a new one, it will see individual sequences. Every sequence is a unique entry.
Stateful=True:
When you go to a stateful layer, You are not going to pass individual sequences anymore. You are going to pass very long sequences divided in small batches. You will need more batches:
batch_x1 = [
[[0],[1],[2]],
[[1],[2],[3]],
[[2],[3],[4]],
[[3],[4],[5]]
]
batch_x2 = [
[[3],[4],[5]], #continuation of batch_x1[0]
[[4],[5],[6]], #continuation of batch_x1[1]
[[5],[6],[7]], #continuation of batch_x1[2]
[[6],[7],[8]] #continuation of batch_x1[3]
]
Both shapes are (4,3,1). And this means that you have:
2 batches
4 individual sequences = this is batch size and it must be constant
6 steps per sequence (3 steps in each batch)
1 feature per step
The stateful layers are meant to huge sequences, long enough to exceed your memory or your available time for some task. Then you slice your sequences and process them in parts. There is no difference in the results, the layer is not smarter or has additional capabilities. It just doesn't consider that the sequences have ended after it processes one batch. It expects the continuation of those sequences.
In this case, you decide yourself when the sequences have ended and call model.reset_states() manually.

An issue of reading different matrices in one YAML file...

I have a problem, it might be trivial to many of you...
I'm reading different images, extract SIFT features and save the features in Yaml file... which I got a file of:
descriptors1: !!opencv-matrix
rows: 342
cols: 128
dt: f
data: [ 0.,.........
....................]
descriptors1: !!opencv-matrix
rows: 393
cols: 128
dt: f
data: [ 0., 0., 3., 62.....
......]
and so on... The first part is the first image information and the second part in the second image information
The think so far is quite satisfy my work...
but when I'm reading it I got only one part which is the first one (i.e reading only the information of the first image (and it's neglecting the rest of the file) :(
This is the way for reading my code
FileStorage fs;
fs.open("cola.yaml", FileStorage::READ);
if (!fs.isOpened())
{
cout << "failed to open " << "test.yaml" << endl;
return 1;
}
Mat descriptors1;
fs["descriptors1"] >> descriptors1;
fs.release();
What I want is to read all the information contained in this file... So I got in the end one matrix has all the information of different images (I'm getting 342*128 matrix) but I want (735*128 matrix)
What should I do?
Save the two descriptors with different names, in the YAML file
by example descritors1 and descriptors2.

How do you document your development? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I am building my first complex app (in RoR) and as I think about passing it on to new programmers, I have been thinking about the best ways to document what I'm building.
How do you like to document your work?
Are there softwares or websites that allow one to easily accumulate sections of documentation, perhaps with tagging for easy reference later on?
If I'm honost: I don't document my apps. When I get new programmers on my team, I give them an introduction to the domain, and that's it. They can read the specs and cucumber features themselves. If there is any special setup required, it's in the README. They can check out the CI configuration too.
That's the power of convention over configuration for ya!
I like to use a wiki. I think it would meet all the goals you named:
an easy way to have various pages and sections
searching and tagging is usually built-in
Plus, there are other features:
You can allow others to help out with the documentation
The docs can grow as they need to: Start out with just a simple one-page site. Then expand when it makes sense.
My two favorites are pbworks.com for private projects: it's free for some uses, and lets you set permissions to private. My other favorite is github, which includes a wiki with every project you create.
I add lots of comments; everywhere. I took the time to write out what logic is happening in human-readable form for every single line of my 500 line music-generation algorithm, and it saved me so much time, and my other friends who were helping.
Here's what I did (as a start):
def __init__(self):
self.chromatic = ['C', ['C#', 'Db'], 'D', ['D#', 'Eb'], 'E', 'F', ['F#', 'Gb'], 'G', ['G#', 'Ab'], 'A', ['A#', 'Bb'], 'B']
self.steps = {}
self.steps['major'] = [2, 2, 1, 2, 2, 2, 1]
self.steps['natural minor'] = [2, 1, 2, 2, 1, 2, 2]
self.steps['harmonic minor'] = [2, 1, 2, 2, 1, 3]
self.steps['melodic minor up'] = [2, 1, 2, 2, 2, 2, 1]
self.steps['melodic minor down'] = [2, 2, 1, 2, 2, 1, 2]
self.steps['dorian'] = [2, 1, 2, 2, 2, 1, 2]
self.steps['mixolydian'] = [2, 2, 1, 2, 2, 1, 2]
self.steps['ahava raba'] = [1, 3, 1, 2, 1, 2, 2]
self.steps['minor penatonic blues'] = [3, 2, 2, 3, 2]
self.list = []
def scale(self, note, name): # Function to generate a scale from the required base note.
if re.sub('[^0-9]', '', note) == '': # Checks for nonexistent octave number
octave = 5 # Defaults to 5
else: # If octave number exists
octave = int(re.sub('[^0-9]', '', note)) # Extracts octave number from note
note = re.sub('[0-9]', '', note) # Strips all numbers from note
scale = [] # Initializes the scale to be empty
for i in rlen(self.chromatic): # Loops through all elements of the Chromatic scale
if self.chromatic[i] is not list: # If the note is just a natural
if note == self.chromatic[i]: scale = [i + 1] # Check if the note is in the chromatic. If it is, add it.
else:
if note in self.chromatic[i]: scale = [i + 1] # If the note is in a key of the chromatic, add it too. It is a sharp/flat.
for i in rlen(self.steps[name]): # Loops through desired scale
scale.append(self.steps[name][i] + scale[i]) # Adds string notes following the algorithm of the scale
scale[i + 1] = scale[i + 1] % len(self.chromatic) # Modulo length of Chromatic scale
It's a start (and an example with cruddy code), but it helps me debug code really quickly.
How about rake doc:app along with expected code commenting?

Resources