Beispiel #1
0
  bool atomic_get_and_clear(unsigned long bit)
  {
    unsigned long idx = bit / Bpl;
    unsigned long b   = bit % Bpl;
    unsigned long v;
    do
      {
        v = _bits()[idx];
      }
    while (!mp_cas(&_bits()[idx], v, v & ~(1UL << b)));

    return v & (1UL << b);
  }
Beispiel #2
0
void set32bitmap (uint32_t * map, unsigned bit) 

{
	map [bit / _bits (* map)] |= HTOLE32 (1 << (bit % _bits (* map)));
	return;
}
    bool DictionaryBased::getInnerCode(const cv::Mat& thres_img, int total_nbits, std::vector<uint64_t>& ids)
    {
        int bits_noborder = static_cast<int>(std::sqrt(total_nbits));
        int bits_withborder = bits_noborder + 2;
        // Markers  are divided in (bits_a+2)x(bits_a+2) regions, of which the inner bits_axbits_a belongs to marker
        // info
        // the external border shoould be entirely black
        cv::Mat nonZeros(bits_withborder,bits_withborder,CV_32SC1);
        cv::Mat nValues(bits_withborder,bits_withborder,CV_32SC1);
        nonZeros.setTo(cv::Scalar::all(0));
        nValues.setTo(cv::Scalar::all(0));
        for (int y = 0; y <  thres_img.rows; y++)
        {
            const uchar *ptr=thres_img.ptr<uchar>(y);
            int my=   float(bits_withborder)*float(y)/ float(thres_img.rows);
            for (int x = 0; x < thres_img.cols; x++)
            {
                int mx=   float(bits_withborder)*float(x)/ float(thres_img.cols);
                if( ptr[x]>125)
                    nonZeros.at<int>(my,mx)++;
                nValues.at<int>(my,mx)++;
            }
        }
        cv::Mat binaryCode(bits_withborder,bits_withborder,CV_8UC1);
        //now, make the theshold
        for(int y=0;y<bits_withborder;y++)
            for(int x=0;x<bits_withborder;x++){
                 if(nonZeros.at<int>(y,x)>nValues.at<int>(y,x)/2)
                    binaryCode.at<uchar>(y,x)=1;
                else
                    binaryCode.at<uchar>(y,x)=0;
            }

        //check if border is completely black
        for (int y = 0; y < bits_withborder; y++)
       {
           int inc = bits_withborder - 1;
           if (y == 0 || y == bits_withborder - 1)
               inc = 1;  // for first and last row, check the whole border
           for (int x = 0; x < bits_withborder; x += inc)
             if (binaryCode.at<uchar>(y,x)!=0 ) return false;
        }

        //take the inner code

        cv::Mat _bits(bits_noborder,bits_noborder,CV_8UC1);
        for(int y=0;y<bits_noborder;y++)
            for(int x=0;x<bits_noborder;x++)
                _bits.at<uchar>(y,x)=binaryCode.at<uchar>(y+1,x+1);

        // now, get the 64bits ids

        int nr = 0;
        do
        {
            ids.push_back(touulong(_bits));
            _bits = rotate(_bits);
            nr++;
        } while (nr < 4);
        return true;
    }
Beispiel #4
0
 void atomic_clear_bit(unsigned long bit)
 {
   unsigned long idx = bit / Bpl;
   unsigned long b   = bit % Bpl;
   atomic_mp_and(&_bits()[idx], ~(1UL << b));
 }
Beispiel #5
0
 void atomic_set_bit(unsigned long bit)
 {
   unsigned long idx = bit / Bpl;
   unsigned long b   = bit % Bpl;
   atomic_mp_or(&_bits()[idx], 1UL << b);
 }
Beispiel #6
0
 unsigned long operator [] (unsigned long bit) const
 {
   unsigned long idx = bit / Bpl;
   unsigned long b   = bit % Bpl;
   return _bits()[idx] & (1UL << b);
 }
Beispiel #7
0
 void set_bit(unsigned long bit)
 {
   unsigned long idx = bit / Bpl;
   unsigned long b   = bit % Bpl;
   _bits()[idx] |= (1UL << b);
 }
Beispiel #8
0
 void clear_bit(unsigned long bit)
 {
   unsigned long idx = bit / Bpl;
   unsigned long b   = bit % Bpl;
   _bits()[idx] &= ~(1UL << b);
 }
Beispiel #9
0
 void bit(unsigned long bit, bool on)
 {
   unsigned long idx = bit / Bpl;
   unsigned long b   = bit % Bpl;
   _bits()[idx] = (_bits()[idx] & ~(1UL << b)) | ((unsigned long)on << b);
 }