⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 contourshape.java

📁 基于MPEG 7 标准,符合未来语义网架构,很值得参考
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        int numPeaks = 1;
        GenericDS Peak_element = l_DDLDescriptionInterface->GetDescription("Peak");
        while (!Peak_element.isNull())
        {
          Peak_element = Peak_element.GetNextSibling("Peak");
          numPeaks++;
        }
        SetNoOfPeaks(numPeaks);

        // And now step through properly to actually read and store the data...

        int i = 1;
        Peak_element = l_DDLDescriptionInterface->GetDescription("Peak");
        while (!Peak_element.isNull())
        {
          int xp, yp;
          Peak_element.GetIntAttribute("peakX", xp);
          Peak_element.GetIntAttribute("peakY", yp);
          SetPeak(i++, (unsigned short)xp, (unsigned short)yp);
          Peak_element = Peak_element.GetNextSibling("Peak");
        }

        // And finally, set the zeroth peak (same as the highest one)

        SetPeak(0, 0, peak0);
      }

      // If the highest peak has a height of zero, this implies NO peaks

      else
        SetNoOfPeaks(0);

      return 0;
        */
    }


    /**
     * Takes two ColorLayout DS and calculates similarity.
     *
     * @return -1.0 if c1 or c2 does not contain a valid ColorLayout DS
     */
    public static double getSimilarity(Element c1, Element c2) {
        double val = -1.0;
        int YCoeff1, YCoeff2, CCoeff1, CCoeff2, YCoeff, CCoeff;
        return val;
    }

    /**
     * Takes two ColorLayout DS and calculates similarity.
     * @return Vector of int[] (yCoeff at Vector.get(0), cbCoeff at Vector.get(1), crCoeff cbCoeff at Vector.get(2)) or null if not valid ColorLayoutDS
     */
    /*
    public static Vector getCoeffs(Element descriptor) {
        Vector vals = null;
        int[] y,cb,cr;
        int numY = 0;
        int numC = 0;
        Namespace mpeg7, xsi;
        mpeg7 = Namespace.getNamespace("", "urn:mpeg:mpeg7:schema:2001");
        xsi = Namespace.getNamespace("xsi", "http://www.w3.org/2001/XMLSchema-instance");
        boolean isValid = false;

        if (descriptor.getChild("YDCCoeff", mpeg7) != null && descriptor.getChild("CbDCCoeff", mpeg7) != null && descriptor.getChild("CrDCCoeff", mpeg7) != null) {
            isValid = true;
            numC = 1;
            numY = 1;
        }
        if (isValid) {
            String str_y, str_cb, str_cr;
        }

        return vals;
    }
    */

    /**
     * Takes two ColorLayout Coeff sets and calculates similarity.
     *
     * @return -1.0 if data is not valid.
     */
    public static double getSimilarity(int[] YCoeff1, int[] CbCoeff1, int[] CrCoeff1, int[] YCoeff2, int[] CbCoeff2, int[] CrCoeff2) {
        int numYCoeff1, numYCoeff2, CCoeff1, CCoeff2, YCoeff, CCoeff;


        return -1;
    }


    private BufferedImage YCrCb2RGB(int[][] rgbSmallImage) {
        BufferedImage br = new BufferedImage(8, 8, BufferedImage.TYPE_INT_RGB);
        WritableRaster r = br.getRaster();
        double rImage, gImage, bImage;
        int pixel[] = new int[3];

        for (int i = 0; i < 64; i++) {
            rImage = ((rgbSmallImage[0][i] - 16.0) * 256.0) / 219.0;
            gImage = ((rgbSmallImage[1][i] - 128.0) * 256.0) / 224.0;
            bImage = ((rgbSmallImage[2][i] - 128.0) * 256.0) / 224.0;

            pixel[0] = Math.max(0, (int) ((1.0 * rImage) + (1.402 * bImage) + 0.5)); //R
            pixel[1] = Math.max(0, (int) ((1.0 * rImage) + (-0.34413 * gImage) + (-0.71414 * bImage) + 0.5));  //G
            pixel[2] = Math.max(0, (int) ((1.0 * rImage) + (1.772 * gImage) + 0.5)); //B

            r.setPixel(i % 8, i / 8, pixel);
        }

        return br;
    }


    private long extractContour(int n, Point ishp) {
        throw new java.lang.UnsupportedOperationException("Method ExtractContour() not implemented");
        /*
      int dr[] = {  0, -1, -1, -1,  0,  1,  1,  1 };
      int dc[] = {  1,  1,  0, -1, -1, -1,  0,  1 };

      int size = 0;
      Point2 *xy = 0;
      MomImage *mask_chan;

      if (m_ImageMedia->a_chan) {
        mask_chan=m_ImageMedia->a_chan;
      }
      else {
        mask_chan=m_ImageMedia->y_chan;
      }
      for (unsigned int r = 0; (r < mask_chan->y) && (size == 0); r++)
      {
    #ifdef WHITE_ON_BLACK
        UChar lastPel = 0;
    #else // !WHITE_ON_BLACK
        UChar lastPel = 255;
    #endif // !WHITE_ON_BLACK
        for (unsigned int c = 0; (c < mask_chan->x) && (size == 0); c++)
        {
          UChar thisPel = *xydata(mask_chan, c, r);

          if (thisPel != lastPel)
          {
            UChar        dir = 0, dir0;
            unsigned int cr = r;
            unsigned int cc = c;
            UChar *p[8];

            do
            {
              p[0] = xydata(mask_chan, cc + 1, cr    );
              p[1] = xydata(mask_chan, cc + 1, cr - 1);
              p[2] = xydata(mask_chan, cc    , cr - 1);
              p[3] = xydata(mask_chan, cc - 1, cr - 1);
              p[4] = xydata(mask_chan, cc - 1, cr    );
              p[5] = xydata(mask_chan, cc - 1, cr + 1);
              p[6] = xydata(mask_chan, cc    , cr + 1);
              p[7] = xydata(mask_chan, cc + 1, cr + 1);

              int i;
              for (i = 0; i < 8; i++)
              {
    #ifdef WHITE_ON_BLACK
                if (p[(dir+3-i)&7] && (*p[(dir+3-i)&7] != 0))
                {
                  if (!p[(dir+4-i)&7])
                  {
                    dir = (dir+3-i)&7;
                    break;
                  }
                  else if (*p[(dir+4-i)&7] == 0)
                  {
                    dir = (dir+3-i)&7;
                    break;
                  }
                }
    #else // !WHITE_ON_BLACK
                if (p[(dir+3-i)&7] && (*p[(dir+3-i)&7] == 0))
                {
                  if (!p[(dir+4-i)&7])
                  {
                    dir = (dir+3-i)&7;
                    break;
                  }
                  else if (*p[(dir+4-i)&7] != 0)
                  {
                    dir = (dir+3-i)&7;
                    break;
                  }
                }
    #endif // !WHITE_ON_BLACK
              }

              if (i == 8)
                break;
              else if (size == 0)
                dir0 = dir;
              else if ((cr == r) && (cc == c) && (dir == dir0))
                break;

              if ((size % 32) == 0)
              {
                Point2 *nxy = new Point2[size+32];
                memset(nxy, 0, (size+32)*sizeof(Point2));
                if (size > 0)
                {
                  memcpy(nxy, xy, size*sizeof(Point2));
                  delete[] xy;
                }
                xy = nxy;
              }

              xy[size].x = cc;
              xy[size].y = cr;
              size++;

              cr += dr[dir]; cc += dc[dir];

            } while (1);
          }
        }
      }

      if (size == 0)
        return 0;

      double per = 0.0;
      double *dst = new double[size];
      for (int i1 = 0; i1 < size; i1++)
      {
        int i2 = (i1 == 0) ? (size-1) : (i1-1);
        double dx = xy[i1].x - xy[i2].x;
        double dy = xy[i1].y - xy[i2].y;
        dst[i1] = sqrt(dx*dx + dy*dy);
        per += dst[i1];
      }

      double del = per / (double)n;

      int cur = 0;
      double oldd = dst[cur];
      ishp[0] = xy[0];
      for (int j = 1; j < n; j++)
      {
        if (oldd > del)
        {
          double f = del / oldd;
          oldd -= del;
          int i1 = (cur < size-1) ? (cur + 1) : 0;
          double xs = f*(xy[i1].x - ishp[j-1].x);
          double ys = f*(xy[i1].y - ishp[j-1].y);
          ishp[j].x = ishp[j-1].x + xs;
          ishp[j].y = ishp[j-1].y + ys;
        }
        else
        {
          double newd = oldd + dst[++cur];
          while (newd < del)
            newd += dst[++cur];
          oldd = newd - del;
          double f = (dst[cur] - oldd) / dst[cur];
          int i1 = (cur < size-1) ? (cur + 1) : 0;
          double xs = f*(xy[i1].x - xy[cur].x);
          double ys = f*(xy[i1].y - xy[cur].y);
          ishp[j].x = xy[cur].x + xs;
          ishp[j].y = xy[cur].y + ys;
        }
      }

      delete[] dst;
      delete[] xy;

      return n;
        */
    }

    private void initPointArray(Point2D.Double[] pointArray) {
        if (pointArray != null) {
            for (int i = 0; i < pointArray.length; i++) {
                Point2D.Double point = pointArray[i];
                if (point == null) {
                    point = new Point2D.Double();
                    pointArray[i] = point;
                }
                point.x = 0;
                point.y = 0;
            }
        }
    }

    private void initIndexCoords(IndexCoords[] indexArray) {
        if (indexArray != null) {
            for (int i = 0; i < indexArray.length; i++) {
                IndexCoords index = indexArray[i];
                if (index == null) {
                    index = new IndexCoords();
                    indexArray[i] = index;
                }
                index.reset();
            }
        }
    }

    private void initEdgeArray(Edge[] edgeArray) {
        if (edgeArray != null) {
            for (int i = 0; i < edgeArray.length; i++) {
                Edge index = edgeArray[i];
                if (index == null) {
                    index = new Edge();
                    edgeArray[i] = index;
                }
                index.reset();
            }
        }
    }


    /**
     * main routine to extract the simularity vector
     *
     * @param pointList List of Point()
     * @return
     */
    private long extractPeaks(List pointList) {
        int n = pointList.size();

        Point2D.Double[] ishp = new Point2D.Double[n];
        ishp = (Point2D.Double[]) pointList.toArray(ishp);

        Point2D.Double[] fshp = new Point2D.Double[n]; // Point() list
        initPointArray(fshp);

        //List peaks = new Vector(CONTOURSHAPE_MAXCSS, 10);    // new Point2[CONTOURSHAPE_MAXCSS];
        Point2D.Double[] peaks = new Point2D.Double[CONTOURSHAPE_MAXCSS];
        initPointArray(peaks);
        int nPeaks = 0;

        Point2D.Double[] dxdy = new Point2D.Double[n];
        Point2D.Double[] d2xd2y = new Point2D.Double[n];
        Point2D.Double[] ang = new Point2D.Double[n];
        Point2D.Double[] fxfy = new Point2D.Double[n];

        initPointArray(dxdy);
        initPointArray(d2xd2y);
        initPointArray(ang);
        initPointArray(fxfy);

        double[] nMinima = new double[n];
        double[] nMaxima = new double[n];
        int nNmin = 0;
        int nNmax = 0;

        double[] oMinima = new double[n];
        double[] oMaxima = new double[n];
        int oNmin = 0;
        int oNmax = 0;

        for (int n1 = 0; n1 < n; n1++) {
            int n2 = (n1 > 0) ? (n1 - 1) : (n - 1);
            dxdy[n1].x = ishp[n1].x - ishp[n2].x;
            dxdy[n1].y = ishp[n1].y - ishp[n2].y;
        }

        int rec = 0, maxrec = (int) (0.262144 * n * n);
        do {
            if (nNmin > 0) {
                //memcpy(oMinima, nMinima, nNmin*sizeof(double));
                System.arraycopy(nMaxima, 0, oMaxima, 0, nNmin);
            }
            oNmin = nNmin;

            if (nNmax > 0) {
                //memcpy(oMaxima, nMaxima, nNmax*sizeof(double));
                System.arraycopy(nMaxima, 0, oMaxima, 0, nNmax);
            }
            oNmax = nNmax;

            ang[0].x = 0.0;
            d2xd2y[0].x = dxdy[0].x - dxdy[n - 1].x;
            d2xd2y[0].y = dxdy[0].y - dxdy[n - 1].y;
            double len = Math.sqrt(dxdy[0].x * dxdy[0].x + dxdy[0].y * dxdy[0].y);
            for (int i1 = 1; i1 < n; i1++) {
                ang[i1].x = len;
                d2xd2y[i1].x = dxdy[i1].x - dxdy[i1 - 1].x;
                d2xd2y[i1].y = dxdy[i1].y - dxdy[i1 - 1].y;
                len += Math.sqrt(dxdy[i1].x * dxdy[i1].x + dxdy[i1].y * dxdy[i1].y);
            }

            double ilen = 1.0 / len;
            for (int i2 = 0; i2 < n; i2++) {
                ang[i2].x *= ilen;
                ang[i2].y = dxdy[i2].x * d2xd2y[i2].y - dxdy[i2].y * d2xd2y[i2].x;
            }

            nNmin = nNmax = 0;
            double y0, x0;
            double x1 = ang[0].x;
            double y1 = ang[0].y;
            for (int j1 = 0; j1 < n; j1++) {
                int j1w = j1 + 1;
                while (j1w >= n) j1w -= n;
                x0 = x1;
                y0 = y1;
                x1 = ang[j1w].x;
                y1 = ang[j1w].y;
                if ((y0 < -CONTOURSHAPE_T) && (y1 >= -CONTOURSHAPE_T)) {
                    for (int j2 = j1 + 1; j2 < j1 + n; j2++) {
                        int j2w = j2;
                        while (j2w >= n) j2w -= n;
                        double y2 = ang[j2w].y;

                        if (y2 < -CONTOURSHAPE_T)
                            break;

                        if (y2 >= CONTOURSHAPE_T) {
                            double x2 = ang[j2w].x;
                            double dx = x2 - x0;
                            while (dx < 0.0) dx += 1.0;
                            double x = -y0 * dx / (y2 - y0) + x0;
                            while (x > 1.0) x -= 1.0;
                            nMinima[nNmin] = x;
                            nNmin++;
                            break;
                        }
                    }
                }
                if ((y0 >= CONTOURSHAPE_T) && (y1 < CONTOURSHAPE_T)) {
                    for (int j2 = j1 + 1; j2 < j1 + n; j2++) {
                        int j2w = j2;
                        while (j2w >= n) j2w -= n;
                        double y2 = ang[j2w].y;

                        if (y2 >= CONTOURSHAPE_T)
                            break;

                        if (y2 < -CONTOURSHAPE_T) {
                            double x2 = ang[j2w].x;
                            double dx = x2 - x0;
                            while (dx < 0.0) dx += 1.0;
                            double x = -y0 * dx / (y2 - y0) + x0;
                            while (x > 1.0) x -= 1.0;
                            nMaxima[nNmax] = x;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -