bool isCameraOffline(cv::Mat& rgb_image) { int r_target = 29; int g_target = 43; int b_target = 182; int threshold = 2; bool offline = true; std::vector<int> x_positions; std::vector<int> y_positions; x_positions.push_back(rgb_image.cols*0.1); x_positions.push_back(rgb_image.cols*0.1); x_positions.push_back(rgb_image.cols*0.2); x_positions.push_back(rgb_image.cols*0.2); x_positions.push_back(rgb_image.cols*0.8); x_positions.push_back(rgb_image.cols*0.8); y_positions.push_back(rgb_image.rows*0.1); y_positions.push_back(rgb_image.rows*0.1); y_positions.push_back(rgb_image.rows*0.2); y_positions.push_back(rgb_image.rows*0.2); y_positions.push_back(rgb_image.rows*0.8); y_positions.push_back(rgb_image.rows*0.8); for (unsigned int i = 0; i < y_positions.size(); i++) { if (abs(getPixelValue(rgb_image,x_positions[i],y_positions[i],0) - r_target) > threshold) offline = false; if (abs(getPixelValue(rgb_image,x_positions[i],y_positions[i],1) - g_target) > threshold) offline = false; if (abs(getPixelValue(rgb_image,x_positions[i],y_positions[i],2) - b_target) > threshold) offline = false; } return offline; }
/*------------------------------------------------------------------------------------------------------------ * */ void Bitmap::fillData(const float* dataR, const float* dataG, const float* dataB) { int index = 0; for (int i = 0; i < mDataSize; i +=3) { mData[i + 0] = getPixelValue(dataB[index]); mData[i + 1] = getPixelValue(dataG[index]); mData[i + 2] = getPixelValue(dataR[index]); index++; } }
/*! \brief Convolucion Sobel en la dirrecion X */ int PixelData::convolveX(int x, int y, int z){ int arr[3][3][3] = { { { -1, 0, 1 }, { -2, 0, 2 }, { -1, 0, 1 } }, { { -2, 0, 2 }, { -4, 0, 4 }, { -2, 0, 2 } }, { { -1, 0, 1 }, { -2, 0, 2 }, { -1, 0, 1 } }, }; /*int arr[3][3][3] = { { { -1, -3, -1 }, { -3, -6, -3 }, { -1, -3, -1 } }, { { 0, 0, 0 }, { 0, 0, 0 }, { 0, 0, 0 } }, { { 1, 3, 1 }, { 3, 6, 3 }, { 1, 3, 1 } }, };*/ int acum = 0; for (int i = 0; i < 3; i++){ for (int j = 0; j < 3; j++){ for (int k = 0; k < 3; k++){ //acum += arr[i][j][k] * pixelData->getPixelValue(x - 1 + k, y + 1 - j, z + 1 - i); acum += arr[i][j][k] * getPixelValue(x - 1 + k, y + 1 - j, z - 1 + i); //std::cout << "val is" << arr[i][j][k] << std::endl; } } } return acum; }
void FEConvolveMatrix::fastSetOuterPixels(PaintingData& paintingData, int x1, int y1, int x2, int y2) { int pixel = (y1 * paintingData.width + x1) * 4; int height = y2 - y1; int width = x2 - x1; int beginKernelPixelX = x1 - m_targetOffset.x(); int startKernelPixelX = beginKernelPixelX; int startKernelPixelY = y1 - m_targetOffset.y(); int xIncrease = (paintingData.width - width) * 4; // Contains the sum of rgb(a) components float totals[3 + (preserveAlphaValues ? 0 : 1)]; // m_divisor cannot be 0, SVGFEConvolveMatrixElement ensures this ASSERT(m_divisor); for (int y = height; y > 0; --y) { for (int x = width; x > 0; --x) { int kernelValue = m_kernelMatrix.size() - 1; int kernelPixelX = startKernelPixelX; int kernelPixelY = startKernelPixelY; int width = m_kernelSize.width(); totals[0] = 0; totals[1] = 0; totals[2] = 0; if (!preserveAlphaValues) totals[3] = 0; while (kernelValue >= 0) { int pixelIndex = getPixelValue(paintingData, kernelPixelX, kernelPixelY); if (pixelIndex >= 0) { totals[0] += m_kernelMatrix[kernelValue] * static_cast<float>(paintingData.srcPixelArray->item(pixelIndex)); totals[1] += m_kernelMatrix[kernelValue] * static_cast<float>(paintingData.srcPixelArray->item(pixelIndex + 1)); totals[2] += m_kernelMatrix[kernelValue] * static_cast<float>(paintingData.srcPixelArray->item(pixelIndex + 2)); } if (!preserveAlphaValues && pixelIndex >= 0) totals[3] += m_kernelMatrix[kernelValue] * static_cast<float>(paintingData.srcPixelArray->item(pixelIndex + 3)); ++kernelPixelX; --kernelValue; if (!--width) { kernelPixelX = startKernelPixelX; ++kernelPixelY; width = m_kernelSize.width(); } } setDestinationPixels<preserveAlphaValues>(paintingData.dstPixelArray, pixel, totals, m_divisor, paintingData.bias, paintingData.srcPixelArray); ++startKernelPixelX; } pixel += xIncrease; startKernelPixelX = beginKernelPixelX; ++startKernelPixelY; } }
/*! \brief Convolucion Sobel en la dirrecion Y */ int PixelData::convolveY(int x, int y, int z){ int arr[3][3][3] = { { { 1, 2, 1 }, { 0, 0, 0 }, { -1, -2, -1 } }, { { 2, 4, 2 }, { 0, 0, 0 }, { -2, -4, -2 } }, { { 1, 2, 1 }, { 0, 0, 0 }, { -1, -2, -1 } }, }; /*int arr[3][3][3] = { { { 1, 3, 1 }, { 0, 0, 0 }, { -1, -3, -1 } }, { { 3, 6, 3 }, { 0, 0, 0 }, { -3, -6, -3 } }, { { 1, 3, 1 }, { 0, 0, 0 }, { 1, 3, 1 } }, };*/ int acum = 0; for (int i = 0; i < 3; i++){ for (int j = 0; j < 3; j++){ for (int k = 0; k < 3; k++){ acum += arr[i][j][k] * getPixelValue(x - 1 + k, y + 1 - j, z - 1 + i); } } } return acum; }
struct matrix* imfilter(struct matrix* image,struct matrix* filter,uint8 operation,uint8 mode){ float tempResult ; float tempPixelValue = 0.0; struct matrix* filteredImage = createMatrix(image->numberOfRows,image->numberOfColumns); #ifdef DEBUG //For debugging initialised a temporary matrix with boundary padded // according to the mode given struct matrix* tempMatrix = createMatrix(filter->numberOfRows,filter->numberOfColumns); #endif //Iterate the rows of the image for (uint16 i = 0; i < image->numberOfRows; ++i) { //Iterate the columns of the image for (uint16 j = 0; j < image->numberOfColumns; ++j) { tempResult = 0.0; //Iterate the rows of the filter for (int l = 0; l < filter->numberOfRows; ++l) { //Iterate the columns of the filter for (int m = 0; m < filter->numberOfColumns; ++m) { // get the pixel value for the given filter mask position(l,m) tempPixelValue = getPixelValue(image,i,j,l-(filter->numberOfRows/2),m-(filter->numberOfColumns/2),mode); #ifdef DEBUG MAT(tempMatrix,l,m) = tempPixelValue; #endif // for convolution operation the filter should be inverted if(operation == CONVOLUTION_OPERATION) { tempResult = tempResult + (tempPixelValue * MAT(filter,(filter->numberOfRows-1-l),(filter->numberOfColumns-1-m))); } // for correlation the filter should be used as it is else { tempResult = tempResult + (tempPixelValue * MAT(filter,l,m)); } } } #ifdef DEBUG printMatrix(tempMatrix); #endif MAT(filteredImage,i,j) = tempResult; } } #ifdef DEBUG printMatrix(filteredImage); #endif return filteredImage; }
/** * @brief conv2d methods defines a convolution operations * @param _input * @param _kernel * @param dst */ void conv2d(Mat _input,Mat _kernel,Mat &_out) { _image_height=_input.rows; _image_width =_input.cols; _kernel_height=_kernel.rows; _kernel_width=_kernel.cols; _image_channels=_input.channels (); _kernel_channels=_kernel.channels (); //dst.create (_image_height,_image_width,_input.type ()); for(int y=0;y<_image_height;y++) { for(int x=0;x<_image_width;x++) { //performs computation for pixels in the valid range Point p=Point(x,y); //local variable used to store convolution sum float value=0; //loop over the rows of the pixel neighborhood //loop over the columns of the pixels neighborhood for(int i=0;i<_kernel_height;i++) for(int j=0;j<_kernel_width;j++) { Point pixel=Point(y+i-(_kernel_height/2),(x+j-(_kernel_width/2))); //condition defines pixels lying within the image borders bool flag=checkPixel (pixel); if(flag==true) { T val=getPixelValue(_input,pixel); value=value+val; } } //setting the result in the destination matrix setPixelValue (_out,Point(x,y),value); } } }
void *NclLayoutConverter::createRegion( DOMElement* parentElement, void *objGrandParent) { LayoutRegion *ncmRegion; string attribute; float percentValue; attribute = XMLString::transcode(parentElement->getAttribute( XMLString::transcode("id"))); // cria nova regiao ncmRegion = new LayoutRegion(attribute); // atributo title if (parentElement->hasAttribute(XMLString::transcode("title"))) { ncmRegion->setTitle(XMLString::transcode(parentElement-> getAttribute(XMLString::transcode("title")))); } // atributo: left if (parentElement->hasAttribute(XMLString::transcode("left"))) { attribute = XMLString::transcode(parentElement->getAttribute( XMLString::transcode("left"))); if (attribute != "") { if (isPercentualValue(attribute)) { percentValue = getPercentualValue(attribute); ncmRegion->setLeft(percentValue, true); } else { double pixelValue; pixelValue = getPixelValue(attribute); ncmRegion->setLeft(pixelValue, false); } } } // atributo: right if (parentElement->hasAttribute(XMLString::transcode("right"))) { attribute = XMLString::transcode(parentElement->getAttribute( XMLString::transcode("right"))); if (isPercentualValue(attribute)) { percentValue = getPercentualValue(attribute); ncmRegion->setRight(percentValue, true); } else { ncmRegion->setRight(getPixelValue(attribute), false); } } // atributo: top if (parentElement->hasAttribute(XMLString::transcode("top"))) { attribute = XMLString::transcode(parentElement->getAttribute( XMLString::transcode("top"))); if (isPercentualValue(attribute)) { percentValue = getPercentualValue(attribute); ncmRegion->setTop(percentValue, true); } else { ncmRegion->setTop(getPixelValue(attribute), false); } } // atributo: bottom if (parentElement->hasAttribute(XMLString::transcode("bottom"))) { attribute = XMLString::transcode(parentElement->getAttribute( XMLString::transcode("bottom"))); if (isPercentualValue(attribute)) { percentValue = getPercentualValue(attribute); ncmRegion->setBottom(percentValue, true); } else { ncmRegion->setBottom(getPixelValue(attribute), false); } } // atributo: width if (parentElement->hasAttribute(XMLString::transcode("width"))) { attribute = XMLString::transcode(parentElement->getAttribute( XMLString::transcode("width"))); if (isPercentualValue(attribute)) { percentValue = getPercentualValue(attribute); ncmRegion->setWidth(percentValue, true); } else { ncmRegion->setWidth(getPixelValue(attribute), false); } } // atributo: height if (parentElement->hasAttribute(XMLString::transcode("height"))) { attribute = XMLString::transcode(parentElement->getAttribute( XMLString::transcode("height"))); if (isPercentualValue(attribute)) { percentValue = getPercentualValue(attribute); ncmRegion->setHeight(percentValue, true); } else { ncmRegion->setHeight(getPixelValue(attribute), false); } } // atributo: zIndex if (parentElement->hasAttribute(XMLString::transcode("zIndex"))) { attribute = XMLString::transcode(parentElement->getAttribute( XMLString::transcode("zIndex"))); ncmRegion->setZIndex(atoi(attribute.c_str())); } // atributo movable if (parentElement->hasAttribute(XMLString::transcode("movable"))) { attribute = XMLString::transcode(parentElement->getAttribute( XMLString::transcode("movable"))); if (XMLString::compareIString(attribute.c_str(), "false")==0) { ncmRegion->setMovable(false); } else { ncmRegion->setMovable(true); } } // atributo resizable if (parentElement->hasAttribute(XMLString::transcode("resizable"))) { attribute = XMLString::transcode(parentElement->getAttribute( XMLString::transcode("resizable"))); if (XMLString::compareIString(attribute.c_str(), "false")==0) { ncmRegion->setResizable(false); } else { ncmRegion->setResizable(true); } } // atributo decorated if (parentElement->hasAttribute(XMLString::transcode("decorated"))) { attribute = XMLString::transcode(parentElement->getAttribute( XMLString::transcode("decorated"))); if (XMLString::compareIString(attribute.c_str(), "false")==0) { ncmRegion->setDecorated(false); } else { ncmRegion->setDecorated(true); } } // retorna regiao return ncmRegion; }
/*! \brief Dada la posicion x,y,z devuelve el pixel de esa posicion pero filtreado con un kernel gausiano * * Se utiliza como prueba para ver el cambio en los gradientes cuando el volumen de datos está difuminado con un filtro gausiano de 5x5x5. * El tiempo computacion empleado en difuminar tal cantidad de datos no justifica la mejora en las direcciones de los gradientes. */ int PixelData::getSmoothPixelValue(int x, int y, int z){ //////Gausain filtern of 5x5x5 int arr[5][5][5] = { { { 0, 0, 0, 0, 0 }, { 0, 0, 1, 0, 0 }, { 0, 1, 4, 1, 0 }, { 0, 0, 1, 0, 0 }, { 0, 0, 0, 0, 0 }, }, { { 0, 1, 4, 1, 0 }, { 1, 4, 16, 4, 1 }, { 4, 7, 26, 7, 4 }, { 1, 4, 16, 4, 1 }, { 0, 1, 4, 1, 0 }, }, { { 1, 4, 7, 4, 1 }, { 4, 16, 26, 16, 4 }, { 7, 26, 41, 26, 7 }, { 4, 16, 26, 16, 4 }, { 1, 4, 7, 4, 1 },}, { { 0, 1, 4, 1, 0 }, { 1, 4, 16, 4, 1 }, { 4, 7, 26, 7, 4 }, { 1, 4, 16, 4, 1 }, { 0, 1, 4, 1, 0 }, }, { { 0, 0, 0, 0, 0 }, { 0, 0, 1, 0, 0 }, { 0, 1, 4, 1, 0 }, { 0, 0, 1, 0, 0 }, { 0, 0, 0, 0, 0 }, }, }; int acum = 0; for (int i = 0; i < 5; i++){ for (int j = 0; j < 5; j++){ for (int k = 0; k < 5; k++){ acum += arr[i][j][k] * getPixelValue(x - 2 + i, y - 2 + j, z - 2 + k); } } } acum = acum / 513; return acum; }