countnonzero seg fault
Hello , I want to use countNonZero , but I am getting a seg fault at the countNnZero line.
vector<Mat> mycompare;
int compareSize = (N / 2) * (N -1);
mycompare.resize( compareSize );
int myCounts [ compareSize ];
int index = 0;
for ( int idx = 0; idx < N; idx++ )
{
for ( int k = idx + 1; k < N; k ++ )
{
mycompare[ index++ ] = ( A[ idx ] == A[ k ] );
myCounts[ index++ ] = countNonZero( mycompare[ index ] );
}
}
OR
Is there a way to use if statement?:
if ( mycompare[ index ] == 255 )
count++;
@LorenaGdL:But , I am setting the
mycompare[0]
, access it in the countNonZero function ,then at the 2nd loop , set themycompare[1]
, access it and so on. ( I am just asking for the if statement )No. The increment of index does not take place at each loop run, but just after it finishes its sentence. Check the printed values for this code:
If I'm not wrong, you'll have Index: 0 and Index: 1, showing than in the same loop run you're trying to access two different indexes
@LorennaGdL:Ok, thanks!( I was a little confused)