I am not very familiar with old opencv codes. I have an IplImage struct:
IplImage *X;
This struct filled up with data that program reads from a device. I want to show it as image in my gui program. But I am not sure which properties I need to use.
EDIT:
Values of IplImage structs all properties with same order in docs(https://docs.opencv.org/3.4/d6/d5b/structIplImage.html):
4
0
0x557684eba3b4
0x557684eba3a4
GRAY
GRAYGRAY
0
16
192
0
�J�ಃ�O�ӳD������I���|�㲏�u������³��t�p�ݲ?�����F�Q�ⲿ���)���ҳ3�7�|�Ӳ������`�����_�I�_�Ͳ���{����E�5�p���(�(�D�|���L�L�W�����Q�,�r�D�L���ز��³�������������ҳ�̲�0������ܳ��,�³dzj�׳��$�|�����u����N���$���Q�ȳ��ܳڳ��������
�J�ಃ�O�ӳD������I���|�㲏�u������³��t�p�ݲ?�����F�Q�ⲿ���)���ҳ3�7�|�Ӳ������`�����_�I�_�Ͳ���{����E�5�p���(�(�D�|���L�L�W�����Q�,�r�D�L���ز��³�������������ҳ�̲�0������ܳ��,�³dzj�׳��$�|�����u����N���$���Q�ȳ��ܳڳ��������
0
49152
0
1
144
0
0
0
127
256
When reading an off-file with cgal it appears that the vertex order of a face decides whether or not it is read in by read_OFF. But the off-file definition does not say anything about the vertex order of a face.
I am reading in self generated off-files using the read_OFF method of cgal:
using Kernel = CGAL::Exact_predicates_inexact_constructions_kernel;
using Point_3 = typename Kernel::Point_3;
...
CGAL::Surface_mesh<Point_3> test_mash;
CGAL::IO::read_OFF(file_name, test_mash);
std::cout << "Number of vertices: " << test_mash.vertices().size()
<< ", Number of faces: " << test_mash.faces().size() << std::endl;
two_faces_read.off:
OFF
4 2 0
1 1 1
2 -2 2
3 3 -3
-4 4 4
3 0 1 2
3 0 3 1
one_face_read.off:
OFF
4 2 0
1 1 1
2 -2 2
3 3 -3
-4 4 4
3 0 1 2
3 0 1 3
Reading two_faces_read.off works as expected, printing:
Number of vertices: 4, Number of faces: 2.
But when i read one_face_read.off i get Number of vertices: 4, Number of faces: 1. The only difference between these two files is the last line, the vertex order of the second face is different. After trying all possible combinations it seems that with 031, 103, 310 2 faces are read in, while with 013, 130, 301 only 1 face is read in.
The off-file specification referenced by cgal does not mention any rules concerning the vertex order of a face.
Why does this happen and how can i ensure that all faces are read in?
one_face_read.off does not define a valid surface mesh has the orientation of the two faces are not compatible. You can use the following function to read points and faces and call CGAL::Polygon_mesh_processing::is_polygon_soup_a_polygon_mesh() to check if the input is a valid surface mesh. The function CGAL::Polygon_mesh_processing::orient_polygon_soup() can be used to fix orientations. CGAL::Polygon_mesh_processing::polygon_soup_to_polygon_mesh() can be used to create the mesh.
I am generating hadamard matrices where for any 2d matrix "M" the next matrix is:
M, M
M,-M
e.g.
Matrix starts with a 1x1 matrix with value "1", such that:
1 (x) 1, 1 = 1, 1
1,-1 1,-1
1, 1 (x) 1, 1 = 1, 1, 1, 1
1,-1 1,-1 1,-1, 1,-1
1, 1,-1,-1
1,-1,-1, 1
And so on... see here
So I have a type:
typedef std::vector<std::vector<char>> matrix_t;
In my constructor I set the matrix to the start value:
hadamard::hadamard() :
m_matrix{{1}}
{
}
So to make the next matrix I decided I could copy the rows (a repeat copy) and then copy the complete matrix (again a repeat copy):
void hadamard::generate_next(matrix_t& matrix, size_t size)
{
if (matrix.size() < size)
{
hadamard::print_matrix(matrix, "before");
// Copy the matrix into 4: M1 | M2
// ---+---
// M3 | M4
// For each inner vector - copy it (double up)
for(auto& row : matrix)
{
// Double up the row
row.insert(row.end(), row.begin(), row.end());
}
// For the outer vector - copy it (double up)
matrix.insert(matrix.end(), matrix.begin(), matrix.end());
// Invert chars in M4 (see diagram above)
TODO
hadamard::print_matrix(matrix, "after");
// Ok, feeling brave, now call recursively...
generate_next(matrix, size);
}
}
Just for completeness here is my print function:
static void print_matrix(matrix_t& matrix, const char * title)
{
printf("%s\r\n", title);
printf("Dimensions - rows: %d, cols: %d\r\n", matrix.size(), matrix[0].size());
int row = 1;
for(auto& line : matrix)
{
printf("NEW LINE\r\n");
int col = 1;
for (auto& item : line)
{
printf("item(%d, %d): %d\r\n", row, col, item);
++col;
}
++row;
}
}
The output I get is like this:
before
Dimensions - rows: 1, cols: 1
NEW LINE
item(1, 1): 1
after
Dimensions - rows: 2, cols: 2
NEW LINE
item(1, 1): 1
item(1, 2): 1
NEW LINE
<HERE SHOULD BE A COPY OF THE PREVIOUS "LINE">
You can see from the output that the inner copy works ok - I guess this is because I am working on std::vector so the inner data is chars.
But the outer copy does not work, I think this is something this vector being a "vector of vectors" (the full type is std::vector<std::vector<char>>).
So basically the line:
// For the outer vector - copy it (double up)
matrix.insert(matrix.end(), matrix.begin(), matrix.end());
does appear to double the size of matrix but it does not copy the data.
Why does it not copy the data? - is it because a deep copy is needed?
Also, what is an efficient way to do this?
In the mean time I am going to manually copy the data across from each row... just to prove to myself that I can do it!
UPDATE
Ok, I "think" I have a really simple fix.... may not be the best way?
for(auto& row : matrix)
{
// Double up the row
row.insert(row.end(), row.begin(), row.end());
// Now copy the row down as well
matrix.insert(matrix.end(), row);
}
But my previous questions still stand!
UPDATE 2
No, the last code change "seemed" to work, at least for the first iteration... but once I start re-cursing through it breaks down...
I have updated the "recursion" so it re-curses, I had not written that code properly... now I get the output:
HADAMARD MATRIX GENERATOR
Generating HM for index 2 - dimensions: 4x4, size: 16
before
Dimensions - rows: 1, cols: 1
1
after
Dimensions - rows: 2, cols: 2
1 1
1 1
before
Dimensions - rows: 2, cols: 2
1 1
1 1
after
Dimensions - rows: 4, cols: 4
1 1 1 1
1 1
1 1 1 1
before
Dimensions - rows: 4, cols: 4
1 1 1 1
1 1
1 1 1 1
after
Dimensions - rows: 8, cols: 8
1 1 1 1 1 1 1 1
1 1
1 1 1 1
1 1 1 1 1 1 1 1
So, its not going well at all! - I am thinking the concatenation of my vectors is all wrong?...
So I'm not sure where the issue is occurring, I feel like this is a basic locking setup. Each thread tries to grab the lock and the one that does can go through the critical section while the other has to wait until the thread releases the lock.
But the odd thing is that my 'numLanesLeft' is sometimes equal for for threads.
For example, it should be:
Thread 1 - 16 - Thread 2 - 16
Thread 1 - 15 - Thread 2 - 14
Thread 1 - 12 - Thread 2 - 13
or something similar all the way down to 0 but I tend to get:
Thread 1 - 16 - Thread 2 - 16
Thread 1 - 14 - Thread 2 - 14
Thread 1 - 12 - Thread 2 - 13
where both threads have the same numLanesLeft
-
void ShooterAction(int rate,Color PlayerColor, int numRound) {
numLanesLeft = Gallery->Count();
// used to get the random lane
int randLane;
int getColor;
// while there are still lanes that haven't been shot at
while(numLanesLeft > 0) {
// only one operation, share lock
pthread_mutex_lock(&mutexLock);
printf("color: %i numLanesLeft: %i \n", PlayerColor, numLanesLeft);
// randomly pick a lane between 0 - 15
randLane = rand() % 16;
// if Rouge picked a lane that has already been fired at, look for a free lane
while(Gallery->Get(randLane) != white) {
randLane = rand() % 16;
}
// set the lane's colour
getColor = Gallery->Set(randLane, PlayerColor);
// set the thread to wait X amount of time to simulate a shot
usleep(1000000/rate);
// decrement the number of lanes
numLanesLeft--;
// upon lock for other threads
pthread_mutex_unlock(&mutexLock);
}
}
Results for printf("color: %i numLanesLeft: %i \n", PlayerColor, numLanesLeft)
color: 1 numLanesLeft: 16
color: 2 numLanesLeft: 15
color: 1 numLanesLeft: 14
color: 2 numLanesLeft: 12
color: 1 numLanesLeft: 12
color: 2 numLanesLeft: 11
color: 1 numLanesLeft: 10
color: 2 numLanesLeft: 9
color: 1 numLanesLeft: 9
color: 2 numLanesLeft: 8
color: 1 numLanesLeft: 7
color: 2 numLanesLeft: 6
color: 1 numLanesLeft: 5
color: 2 numLanesLeft: 4
color: 1 numLanesLeft: 3
color: 2 numLanesLeft: 2
color: 1 numLanesLeft: 1
the problem is in the first line in the method
numLanesLeft = Gallery->Count();
numLanesLeft is a global variable than being accessed and updated by more than one thread without any lock.
if first thread start and did 16, 15, 14 and only after than second thread starting running he will reset the value of numLanesLeft at the beginning of the method.
second issue: the condition (numLanesLeft > 0) might change between the time the thread checked it and starting waiting for the lock and the lock being released, so inside the critical second it more safe to check if the condition (numLanesLeft > 0) is still valid before starting to run it.
other than that i can't find any reason why you are having such results !!
Note: its recommended to use "cout" instead of "printf" in c++
Now I am creating my own classifier for face detection.now I want to train the classifier.So when I give the command 'opencv_haartraining -data facehaar -vec vecfile.vec -bg negatives.txt -npos 3 -nneg 5 -nstages 30 -w 30 -h 32' it shows like this.What is this error?I don't understand?Could any one help me?
Data dir name: facehaar
Vec file name: vecfile.vec
BG file name: negatives.txt, is a vecfile: no
Num pos: 3
Num neg: 5
Num stages: 30
Num splits: 1 (stump as weak classifier)
Mem: 200 MB
Symmetric: TRUE
Min hit rate: 0.995000
Max false alarm rate: 0.500000
Weight trimming: 0.950000
Equal weights: FALSE
Mode: BASIC
Width: 30
Height: 32
Applied boosting algorithm: GAB
Error (valid only for Discrete and Real AdaBoost): misclass
Max number of splits in tree cascade: 0
Min number of positive samples per cluster: 500
Required leaf false alarm rate: 9.31323e-10
Tree Classifier
Stage
+---+
| 0|
+---+
Number of features used : 234720
Parent node: NULL
*** 1 cluster ***
POS: 3 3 1.000000
Invalid background description file.