void KMfilterCenters::moveToCentroid() // move center to cluster centroid { if (!valid) computeDistortion(); // compute sums if needed for (int j = 0; j < kCtrs; j++) { int wgt = weights[j]; // weight of this center if (wgt > 0) { // update only if weight > 0 for (int d = 0; d < getDim(); d++) { ctrs[j][d] = (1 - dampFactor) * ctrs[j][d] + dampFactor * sums[j][d]/wgt; } } } invalidate(); // distortions now invalid }
void ofxMultiplexer::initializeMultiplexer() { deinitializeMultiplexer(); stitchedFrame = (unsigned char*)malloc(stitchedFrameWidth * stitchedFrameHeight * sizeof(unsigned char)); offsetMap = (unsigned int**)malloc(cameraGridWidth*cameraGridHeight * sizeof(unsigned int*)); weightMap = (float**)malloc(cameraGridWidth*cameraGridHeight * sizeof(float*)); cameraFrames = (unsigned char**)malloc(cameraGridWidth*cameraGridHeight * sizeof(unsigned char*)); cameraCalibrationPoints = (vector2df**)malloc(cameraGridWidth*cameraGridHeight * sizeof(vector2df*)); blackCapturingMode = (bool*)malloc(cameraGridWidth*cameraGridHeight*sizeof(bool)); cameras = (ofxCameraBase**)malloc(cameraGridWidth*cameraGridHeight * sizeof(ofxCameraBase*)); cameraMap = (unsigned char**)malloc(4 * sizeof(unsigned char*)); cameraFramesWidth = (int*)malloc(cameraGridWidth*cameraGridHeight * sizeof(int)); cameraFramesHeight = (int*)malloc(cameraGridWidth*cameraGridHeight * sizeof(int)); for (int i=0;i<4;i++) { cameraMap[i] = (unsigned char*)malloc(stitchedFrameWidth*stitchedFrameHeight*sizeof(unsigned char)); memset((void*)cameraMap[i],NULL_CAMERA,stitchedFrameWidth*stitchedFrameHeight*sizeof(unsigned char)); } for (int i=0;i<cameraGridWidth*cameraGridHeight;i++) { cameraCalibrationPoints[i] = (vector2df*)malloc((calibrationGridWidth+1)*(calibrationGridHeight+1)*sizeof(vector2df)); cameras[i] = NULL; offsetMap[i] = (unsigned int*)malloc(stitchedFrameWidth * stitchedFrameHeight * sizeof(unsigned int)); memset(offsetMap[i],0,stitchedFrameWidth * stitchedFrameHeight * sizeof(unsigned int)); weightMap[i] = (float*)malloc(stitchedFrameWidth * stitchedFrameHeight * sizeof(float)); memset(weightMap[i],0,stitchedFrameWidth * stitchedFrameHeight * sizeof(float)); blackCapturingMode[i] = true; int newCameraIndex = -1; for (int j=0;j<cameraBasesCalibration.size();j++) { if (cameraBasesCalibration[j]->index == i) newCameraIndex = j; } if (newCameraIndex>=0) { unsigned int cameraWidth,cameraHeight; unsigned char cameraDepth,cameraPixel; cameraBasesCalibration[newCameraIndex]->camera->getCameraSize(&cameraWidth,&cameraHeight,&cameraDepth,&cameraPixel); cameraBasesCalibration[newCameraIndex]->camera->resumeCamera(); cameraFramesWidth[i] = cameraWidth; cameraFramesHeight[i] = cameraHeight; if (cameraBasesCalibration[newCameraIndex]->calibrationPoints.size() == (calibrationGridWidth+1)*(calibrationGridHeight+1)) { for (int j=0;j<(calibrationGridWidth+1)*(calibrationGridHeight+1);j++) { cameraCalibrationPoints[i][j].X = cameraBasesCalibration[newCameraIndex]->calibrationPoints[j].X * cameraFramesWidth[i]; cameraCalibrationPoints[i][j].Y = cameraBasesCalibration[newCameraIndex]->calibrationPoints[j].Y * cameraFramesHeight[i]; } } else { cameraBasesCalibration[newCameraIndex]->calibrationPoints.clear(); float dx = cameraFramesWidth[i] / calibrationGridWidth; float dy = cameraFramesHeight[i] / calibrationGridHeight; int P = 0; for (int y=0;y<=calibrationGridHeight;y++) { for (int x=0;x<=calibrationGridWidth;x++) { cameraCalibrationPoints[i][P].X = dx * x; cameraCalibrationPoints[i][P].Y = dy * y; P++; } } } blackCapturingMode[i] = false; cameras[i] = cameraBasesCalibration[newCameraIndex]->camera; } else { cameraFramesWidth[i] = 320; cameraFramesHeight[i] = 240; float dx = cameraFramesWidth[i] / calibrationGridWidth; float dy = cameraFramesHeight[i] / calibrationGridHeight; int P = 0; for (int y=0;y<=calibrationGridHeight;y++) { for (int x=0;x<=calibrationGridWidth;x++) { cameraCalibrationPoints[i][P].X = dx * x; cameraCalibrationPoints[i][P].Y = dy * y; P++; } } } cameraFrames[i] = (unsigned char*)malloc(cameraFramesWidth[i] * cameraFramesHeight[i] * sizeof(unsigned char)); memset(cameraFrames[i],1,cameraFramesWidth[i] * cameraFramesHeight[i] * sizeof(unsigned char)); } actualStitchedFrameWidth = stitchedFrameWidth; actualStitchedFrameHeight = stitchedFrameHeight; actualCameraGridWidth = cameraGridWidth; actualCameraGridHeight = cameraGridHeight; actualCalibrationGridWidth = calibrationGridWidth; actualCalibrationGridHeight = calibrationGridHeight; computeDistortion(); }