void arrayTests() { int arr[16]; int arr1[16]; int res[16]; time_t t; int size = sizeof(arr)/sizeof(arr[0]); srand((unsigned) time(&t)); fillRand3(arr, size); srand((unsigned) time(&t) + 1); fillRand3(arr1, size); printf("Array 1 was filled %scorrecly :\n", checkRand3(arr, size) ? "" : "in"); printArr(arr, size); printf("Array 2 was filled %scorrecly :\n", checkRand3(arr1, size) ? "" : "in"); printArr(arr1, size); printf("Array 1:\n"); printf("Max value is %i\nIts index is %i\n", max(arr, size), maxIndex(arr, size)); printf("Mean value is %f\nThe closest number is at the index %i\n", meanValue(arr, size), meanIndex(arr, size)); printf("Number %i was find maximum times in our array\n", maxOccurance(arr, size)); printf("\nArray 2:\n"); printf("Max value is %i\nIts index is %i\n", max(arr1, size), maxIndex(arr1, size)); printf("Mean value is %f\nThe closest number is at the index %i\n", meanValue(arr1, size), meanIndex(arr1, size)); printf("Number %i was find maximum times in our array\n", maxOccurance(arr1, size)); printf("\nArrays 1 and 2 are %s equal\n", diff(arr, arr1, res, size) ? "" : "not"); printf("The result if adding Array 1 and Array 2 is :\n"); add(arr, arr1, res, size); printArr(res, size); printf("Corresponding elements of Array 1 and Array 2 are %s less or equal\n", lteq(arr, arr1, size) ? "" : "not"); printf("The result of logical OR to corresponding elements of Array 1 and Array 2:\n"); lor(arr, arr1, res,size); printArr(res, size); }
int main(){ int size = 6; int arr[size]; int arr1[6]={1,2,3,4,5,6}; int arr2[6]={-11,-12,-13,-14,-15,-16}; int res[6]; int i; fillRand3(arr, size); for (i = 0; i < size; i++) printf("%d\t", arr[i]); printf("\nrez = %d\n",checkRand3(arr, size)); printf("sred = %.3f\n",meanValue(arr, size)); printf("min = %d\n", minValue(arr, size)); printf("index= %i\n", meanIndex(arr, size)); printf("index = %d\n", minIndex(arr, size)); printf("elem = %d\n", maxOccurance(arr, size)); printf("res = %d\n", diff(arr1, arr2, res, size)); sub(arr1, arr2, res, size); for (i=0;i<size;i++) printf("%d\t", res[i]); printf("\neq= %d\n", eq(arr1, arr2, size)); land(arr1, arr2, res, size); for (i=0;i<size;i++) printf("%d\t", res[i]); return 0; }
int main(){ int size = 8; int arr[size]; int arr1[8]={1,2,3,4,5,6,7,8}; int arr2[8]={11,12,13,14,15,16,17,18}; int res[8]; int index; int i; srand(time(NULL)); fillRand1(arr, size); for (i=0;i<size;i++) printf("%d\t", arr[i]); checkRand1(arr, size); printf("\n CheckRand = %d\n",checkRand1(arr, size)); meanValue(arr, size); printf("Average value = %.3f\n",meanValue(arr, size)); minValue(arr, size); printf("Min value = %d\n", minValue(arr, size)); meanIndex(arr, size); printf("Index values near the average value = %d\n", meanIndex(arr, size)); minIndex(arr, size); printf("Min index = %i \n ", minIndex(arr,size)); maxOccurance(arr, size); printf("Value, which is most common in the array = %d\n", maxOccurance(arr, size)); diff(arr1, arr2, res, size); printf("Diff = %d\n", diff(arr1, arr2, res, size)); mult(arr1,arr2,res,size); printf("Mult\n"); for (i=0;i<size;i++) printf("%d\t", res[i]); printf("\n"); lt(arr1,arr2,size); printf("Less than = %d\n", lt(arr1, arr2, size)); land(arr1,arr2,res,size); for (i=0;i<size;i++) printf("%d\t", res[i]); return 0; }
int main(void) { srand(time(NULL)); int arr[12]; int arr2[12]; int res[12]; int size = 12; int i; int check; fillRand3(arr, 12); for (i = 0; i < 12; i++) { printf("%d ", arr[i]); } puts("- First randomly generated array\n"); check = checkRand3(arr, size); printf("%d", check); puts(" - Is is really consist of only [0..1]\n"); printf("%.10f", meanValue(arr, size)); puts(" - Average value of the array\n"); check = maxValue(arr, size); printf("%d", check); puts(" - Maximal element of the array\n"); check = meanIndex(arr, size); printf("%d", check); puts(" - Index of the first element most close to the average value\n"); check = maxIndex(arr, size); printf("%d", check); puts(" - Index of the first maximal number\n"); check = maxOccurance(arr, size); printf("%d", check); puts(" - The most occurable element of the array\n"); fillRand3(arr2, size); for (i = 0; i < 12; i++) { printf("%d ", arr2[i]); } puts("- Second randomly generated array\n"); check = diff(arr, arr2, res, size); printf("%d", check); puts(" - Is it different from the first one or not\n"); sub(arr, arr2, res, size); for (i = 0; i < 12; i++) { printf("%d ", res[i]); } puts("- Result array consisting of arr[i]-arr2[i]\n"); check = eq(arr, arr2, size); printf("%d", check); puts(" - Whether arrays are equal or not\n"); lor(arr, arr2, res, size); for (i = 0; i < 12; i++) { printf("%d ", res[i]); } puts("- Result array consisting of arr[i]||arr2[i]\n"); return 0; }
int meanIndex(int arr[], int size){ int i,min,in,s; s=meanValue( arr, size); for(i=size;i>=0;i--){ if(min>=abs(arr[i]-s)){ min=arr[i]; in=i; } } return in; }
int meanIndex(int arr[], int size){ int i; float mean = meanValue(arr, size); int index; float delta= fabs(arr[0] - mean); for(i=1;i<size; i++){ float deltaMean = fabs(mean - arr[i]); if(deltaMean<delta){ index = i; delta = deltaMean; } } return index; }
int meanIndex(int arr[], int size){ int i; float dif; float mean = meanValue(arr,size); int meanIndex = 0; dif = abs(mean-arr[0]); for(i=1; i<size; i++){ if((dif>abs(mean - arr[i]))&&((mean - arr[i] != 0))){ dif = abs(mean - arr[i]); meanIndex = i; } } return meanIndex; }
std::tuple<QVector<double>, QVector<double> > WindowFilter::operator()(const QVector<double> &x, const QVector<double> &y) { QVector<double> retX = x; QVector<double> retY; int leftWidth = (mWindowWidth - 1) / 2; int rightWidth = mWindowWidth - leftWidth - 1; for (int i = 0; i < y.size(); ++i) { if (x[i] < mBeginTime || x[i] > mEndTime) { retY.push_back(y[i]); continue; } retY.push_back(meanValue(y, i - leftWidth, i + rightWidth + 1)); } return std::tuple<QVector<double>, QVector<double> >(retX, retY); }
int meanIndex(int arr[], int size) { float mean = meanValue(arr, size); int index = 0; float median = fabs(mean - arr[0]); int i; for (i = 1; i < size; i++) { float tempMedian = fabs(mean - arr[i]); if (tempMedian < median) { index = i; median = tempMedian; } } return index; }
int eyelidDistance(Mat eye, double threshold) { int i; int j; int m = eye.rows; int n = eye.cols; Mat strechedEye = stretchHistogram(&eye); vector<int> summary = sum(&strechedEye, 2); vector<int> eyebrowPeaks; vector<int> eyebrowLocs; findPeaks(&summary, &eyebrowLocs, &eyebrowPeaks); Mat eyeBinary = binarize(&strechedEye, 55); if (!eyebrowLocs.empty()) { if (eyebrowLocs[0] != 1 && eyebrowLocs[0] < round(m / 2.2)) { eyeBinary.rowRange(0, eyebrowLocs[0] - 1) = 1; } } vector<double> mBinary = meanValue(&eyeBinary, 2); vector<double> sigmaBinary(m); for (i = 0; i < m; i++) { double tmpSum = 0; for (j = 0; j < n; j++) { tmpSum += (eyeBinary.at<uchar>(i, j) - mBinary[i])*(eyeBinary.at<uchar>(i, j) - mBinary[i]); } sigmaBinary[i] = tmpSum / n; } vector<double> difVarBinary = diff(&sigmaBinary); vector<double> pksBinaryPositive; vector<int> locsBinaryPositive; vector<double> pksBinaryNegative; vector<int> locsBinaryNegative; findPeaks(&difVarBinary, &locsBinaryPositive, &pksBinaryPositive); findPeaks(&(negateVector(difVarBinary)), &locsBinaryNegative, &pksBinaryNegative); vector<double> pksBinary = pksBinaryPositive; vector<double> negatedPeaks = negateVector(pksBinaryNegative); pksBinary.insert(pksBinary.end(), negatedPeaks.begin(), negatedPeaks.end()); vector<int> locsBinary = locsBinaryPositive; locsBinary.insert(locsBinary.end(), locsBinaryNegative.begin(), locsBinaryNegative.end()); int loc1, loc2; getDistance(pksBinary, locsBinary, &loc1, &loc2); int distance = abs(loc2 - loc1); double percent = 0; if (distance < threshold) { return 0; } else { if (loc1 != 0 || loc2 != 0) { if (loc1 < loc2) { Mat extract = eyeBinary.rowRange(loc1, loc2); vector<int> sumH = sum(&invert(&extract), 2); int boundariesH1; int boundariesH2; int boundariesV1; int boundariesV2; getBigInterval(sumH, &boundariesH1, &boundariesH2, 0.85); vector<int> sumV = sum(&invert(&extract), 1); getBigInterval(sumV, &boundariesV1, &boundariesV2, 0.65); Mat cut = extract(Range(boundariesH1, boundariesH2), Range(boundariesV1, boundariesV2)); percent = 100 * (sum(cut))[0] / (double)(cut.rows * cut.cols); } } if (percent > 25) { return 0; } else { return distance; } } }
int main(){ int i, x, min, ind, ind2, chas, pr, pr2, riz, riz2; float ser; int v=4; int myMatrix[4] = { 1,2,3,4 }; int myMatrix2[4] = { 1,2,3,4 }; int myMatrix3[4] = { 1,2,3,4 }; int myMatrix4[4] = { 0,0,0,0 }; int log1[4] = { 0,1,0,1 }; int log2[4] = { 1,1,0,0 }; puts("Proizvolnaia matriza"); srand(time(NULL)); fillRand2(myMatrix, v); for(i = 0; i<4; i++){ printf("%d\n",myMatrix[i]); } puts(" \n"); x = checkRand2(myMatrix, v); printf("Vse elementi ot -255 do 255?\n %d\n", x); puts(" \n"); ser = meanValue(myMatrix, v); printf("Srednee arifmeticheskoe\n %f\n", ser); puts(" \n"); min = minValue(myMatrix, v); printf("Minimalnii element masiva\n %d\n", min); puts(" \n"); ind = meanIndex(myMatrix, v); printf("index pervogo element, nablizhenii do ser ar\n %d\n", ind); puts(" \n"); ind2 = minIndex(myMatrix, v); printf("index pervogo minimalnogo\n %d\n", ind2); puts(" \n"); chas = maxOccurance(myMatrix, v); printf("samii chastii element (bolshii)\n %d\n", chas); puts(" \n"); pr = diff(myMatrix, myMatrix2 , myMatrix3, v); printf("vse raznizi = 0?\n %d\n", pr); puts(" \n"); pr2 = diff(myMatrix, myMatrix, myMatrix3, v); printf("vse raznizi = 0? (sdelano narochno)\n %d\n", pr2); puts(" \n"); puts("Raznica 2-x matriz"); sub(myMatrix, myMatrix2, myMatrix3, v); for(i = 0; i<4; i++){ printf("%d\n",myMatrix3[i]); } puts(" \n"); riz = lt(myMatrix, myMatrix2, v); printf("vse menshe?\n %d\n", riz); puts(" \n"); riz2 = lt(myMatrix4, myMatrix2, v); printf("vse menshe?(narochno)\n %d\n", riz2); puts(" \n"); puts("logicheskii AND"); land(log1, log2, myMatrix3, v); for(i = 0; i<4; i++){ printf("%d\n",myMatrix3[i]); } puts(" \n"); return 0; }
int command(int n, int m, int mat[n][m]){ int pink = BACKGROUND_BLUE | BACKGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_BLUE | FOREGROUND_INTENSITY, green = BACKGROUND_BLUE | BACKGROUND_INTENSITY | FOREGROUND_GREEN | FOREGROUND_INTENSITY, yellow = BACKGROUND_BLUE | BACKGROUND_INTENSITY | FOREGROUND_RED | FOREGROUND_GREEN | FOREGROUND_INTENSITY; int command = 0, y; char s[50]; baseprint(2, 15, pink); printf("Please, enter your command :"); while(command != 2){ baseprint(2, 16, yellow); scanf("%s", s); fflush(stdin); if(strcmp(s,"help") == 0){ command = 1; } else if(strcmp(s,"end") == 0){ command = 2; } else if(strcmp(s,"null") == 0){ command = 3; } else if(strcmp(s,"random") == 0){ command = 4; } else if(strcmp(s,"change") == 0){ command = 5; } else if(strcmp(s,"flipH") == 0){ command = 6; } else if(strcmp(s,"mean") == 0){ command = 7; } else if(strcmp(s,"sum") == 0){ command = 8; } else if(strcmp(s,"change1") == 0){ command = 9; } else if(strcmp(s,"change2") == 0){ command = 10; } else if(strcmp(s,"change3") == 0){ command = 11; } else{ command = 0; baseprint(2, 17, pink); printf(" ERROR, try again!"); deleting(16); baseprint(2, 16, pink); getch(); } deleting(17); switch (command){ case 1: help(); getch(); break; case 2: end(); break; case 3: null(n, m, mat); break; case 4: random(n, m, mat); break; case 5: elchange(n, m, mat); break; case 6: flipH(n, m, mat); break; case 7: meanValue(n, m, mat); getch(); break; case 8: elementsSum(n, m, mat); getch(); break; case 9: elementsChange1(n, m, mat); break; case 10: elementsChange2(n, m, mat); break; case 11: columnChange(n, m, mat); break; case 0: break; } newcommand(); } }