/* extract the faces from an image for given face rectangles
483084
function getFacesFromLocations(img, rects, faceSize = 150) {
      return Promise.all(
        rects.map(rect => faceLandmarkPredictor.predictAsync(img, rect))
      )
        .then(shapes => fr.extractImageChips(img, fr.getFaceChipDetails(shapes, faceSize)))
    }
1372937
def _get_corners(self, image):
        """"""
        temp = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
        ret, corners = cv2.findChessboardCorners(temp,
                                                 (self.rows, self.columns))
        if not ret:
            raise ChessboardNotFoundError("No chessboard could be found.")
        cv2.cornerSubPix(temp, corners, (11, 11), (-1, -1),
                         (cv2.TERM_CRITERIA_MAX_ITER + cv2.TERM_CRITERIA_EPS,
                          30, 0.01))
        return corners
280265
def face_angles_sparse(mesh):
    
    matrix = coo_matrix((mesh.face_angles.flatten(),
                         (mesh.faces_sparse.row, mesh.faces_sparse.col)),
                        mesh.faces_sparse.shape)
    return matrix
958442
function(array){
                array = array || [];
                var i = 0;
                for(f=0; f<this.faces.length; f++){
                    var face = this.faces[f];
                    array[i++] = face.uvA ? face.uvA.x : 0;
                    array[i++] = face.uvA ? face.uvA.y : 0;
                    array[i++] = face.uvB ? face.uvB.x : 0;
                    array[i++] = face.uvB ? face.uvB.y : 0;
                    array[i++] = face.uvC ? face.uvC.x : 0;
                    array[i++] = face.uvC ? face.uvC.y : 0;
                }

                return array;
            }
854125
def _extract_intensities(image, mask = slice(None)):
    
    return numpy.array(image, copy=True)[mask].ravel()
897224
function getRectangleFromImagePlane(imagePlane) {
  // Get the points
  const topLeft = imagePointToPatientPoint(
    {
      x: 0,
      y: 0,
    },
    imagePlane
  );
  const topRight = imagePointToPatientPoint(
    {
      x: imagePlane.columns,
      y: 0,
    },
    imagePlane
  );
  const bottomLeft = imagePointToPatientPoint(
    {
      x: 0,
      y: imagePlane.rows,
    },
    imagePlane
  );
  const bottomRight = imagePointToPatientPoint(
    {
      x: imagePlane.columns,
      y: imagePlane.rows,
    },
    imagePlane
  );

  // Get each side as a vector
  const rect = {
    top: new external.cornerstoneMath.Line3(topLeft, topRight),
    left: new external.cornerstoneMath.Line3(topLeft, bottomLeft),
    right: new external.cornerstoneMath.Line3(topRight, bottomRight),
    bottom: new external.cornerstoneMath.Line3(bottomLeft, bottomRight),
  };

  return rect;
}
585953
def _n_rectangles(obj):
    '''
    
    '''
    return sum(_total_rectangles(neu) for neu in obj.neurites) \
        if hasattr(obj, 'neurites') else _total_rectangles(obj)
11422
def extract_exif(self):
        '''
        
        '''
        width, height = self.extract_image_size()
        make, model = self.extract_make(), self.extract_model()
        orientation = self.extract_orientation()
        geo = self.extract_geo()
        capture = self.extract_capture_time()
        direction = self.extract_direction()
        d = {
            'width': width,
            'height': height,
            'orientation': orientation,
            'direction': direction,
            'make': make,
            'model': model,
            'capture_time': capture
        }
        d['gps'] = geo
        return d
969212
function addFaces(faces, className, numJitters = 0) {
      if (!faces || !faces.length) {
        throw new Error('train - expected an array containing atleast one face image')
      }

      if (!className) {
        throw new Error('train - expected a class name')
      }

      const faceDescriptors = flatten(
        faces.map(f => getJitteredFaces(f, numJitters).map(jf => getNet().computeFaceDescriptor(jf)))
      )

      addFaceDescriptors(faceDescriptors, className)
    }
870696
def handle_sub_rectangles(self, images, sub_rectangles):
        
        image_info = [im.info for im in images]
        if isinstance(sub_rectangles, (tuple, list)):
            # xy given directly

            # Check xy
            xy = sub_rectangles
            if xy is None:
                xy = (0, 0)
            if hasattr(xy, '__len__'):
                if len(xy) == len(images):
                    xy = [xxyy for xxyy in xy]
                else:
                    raise ValueError("len(xy) doesn't match amount of images.")
            else:
                xy = [xy for im in images]
            xy[0] = (0, 0)

        else:
            # Calculate xy using some basic image processing

            # Check Numpy
            if np is None:
                raise RuntimeError("Need Numpy to use auto-sub_rectangles.")

            # First make numpy arrays if required
            for i in range(len(images)):
                im = images[i]
                if isinstance(im, Image.Image):
                    tmp = im.convert()  # Make without palette
                    a = np.asarray(tmp)
                    if len(a.shape) == 0:
                        raise MemoryError("Too little memory to convert PIL image to array")
                    images[i] = a

            # Determine the sub rectangles
            images, xy = self.get_sub_rectangles(images)

        # Done
        return images, xy, image_info
1125839
def from_images(cls, images, weights=None, filter=None, wrap=None,
		aspect_adjust_width=False, aspect_adjust_height=False):
		
		import pyglet
		atlas, textures = _atlas_from_images(images)
		texturizer = cls(
			atlas.texture.id, [tex.tex_coords for tex in textures],
			weights, filter or pyglet.gl.GL_LINEAR, wrap or pyglet.gl.GL_CLAMP,
			aspect_adjust_width, aspect_adjust_height)
		texturizer.atlas = atlas
		texturizer.textures = textures
		return texturizer
694428
protected double[][] extractFeaturesInternal(BufferedImage image) {

		double[][] descriptions = harder(image);
		if (!perBandNormalization) {
			// if perBandNormalization is off then do a final L2 normalization
			for (int i = 0; i < descriptions.length; i++) {
				Normalization.normalizeL2(descriptions[i]);
				// SurfDescribeOps.normalizeFeatures(descriptions[i]);
			}
		}
		return descriptions;
	}
730573
function predict(face) {
      const inputDescriptor = getNet().computeFaceDescriptor(face)
      return getDescriptorsByClass().map(ds => ({
        className: ds.className,
        distance: computeMeanDistance(ds.faceDescriptors, inputDescriptor)
      }))
    }
705584
function _getNeighborPixels(coord, imgSize, imgCols) {
    var res = [], pos;

    if (coord.x > 0 && coord.y > 0) { // tlPx
        pos = {
            x: coord.x - 1,
            y: coord.y - 1
        };
        res.push({
            coord: pos,
            color: _getColorByXY(pos, imgSize, imgCols)
        });
    }

    if (coord.y > 0) { // tPx
        pos = {
            x: coord.x,
            y: coord.y - 1
        };
        res.push({
            coord: pos,
            color: _getColorByXY(pos, imgSize, imgCols)
        });
    }

    if (coord.x < imgSize.w && coord.y > 0) { // trPx
        pos = {
            x: coord.x + 1,
            y: coord.y - 1
        };
        res.push({
            coord: pos,
            color: _getColorByXY(pos, imgSize, imgCols)
        });
    }

    if (coord.x < imgSize.w) { // rPx
        pos = {
            x: coord.x + 1,
            y: coord.y
        };
        res.push({
            coord: pos,
            color: _getColorByXY(pos, imgSize, imgCols)
        });
    }

    if (coord.x < imgSize.w && coord.y < imgSize.h) { // brPx
        pos = {
            x: coord.x + 1,
            y: coord.y + 1
        };
        res.push({
            coord: pos,
            color: _getColorByXY(pos, imgSize, imgCols)
        });
    }

    if (coord.y < imgSize.h) { // bPx
        pos = {
            x: coord.x,
            y: coord.y + 1
        };
        res.push({
            coord: pos,
            color: _getColorByXY(pos, imgSize, imgCols)
        });
    }

    if (coord.x > 0 && coord.y < imgSize.h) { // blPx
        pos = {
            x: coord.x - 1,
            y: coord.y + 1
        };
        res.push({
            coord: pos,
            color: _getColorByXY(pos, imgSize, imgCols)
        });
    }

    if (coord.x > 0) { // lPx
        pos = {
            x: coord.x - 1,
            y: coord.y
        };
        res.push({
            coord: pos,
            color: _getColorByXY(pos, imgSize, imgCols)
        });
    }

    return res;
}
1024457
def mesh(faces, coordinates, meta_data=None, properties=None):
    '''
    
    '''
    return Mesh(faces, coordinates, meta_data=meta_data, properties=properties)
741879
def find_face_neighbors(face)
      raise "not a face" unless face.is_a?(Face)
      neighbors = find_neighbors(face.vertices)
      neighbors - [face]
    end
84752
def Rectangle(p1=(0, 0, 0), p2=(2, 1, 0), c="k", bc="dg", lw=1, alpha=1, texture=None):
    """"""
    p1 = np.array(p1)
    p2 = np.array(p2)
    pos = (p1 + p2) / 2
    length = abs(p2[0] - p1[0])
    height = abs(p2[1] - p1[1])
    return Plane(pos, [0, 0, -1], length, height, c, bc, alpha, texture)