Github user viirya commented on a diff in the pull request:
https://github.com/apache/spark/pull/20168#discussion_r161664859
--- Diff: python/pyspark/ml/image.py ---
@@ -55,25 +72,66 @@ def imageSchema(self):
"""
if self._imageSchema is None:
- ctx = SparkContext._active_spark_context
+ ctx = SparkContext.getOrCreate()
jschema =
ctx._jvm.org.apache.spark.ml.image.ImageSchema.imageSchema()
self._imageSchema = _parse_datatype_json_string(jschema.json())
return self._imageSchema
@property
def ocvTypes(self):
"""
- Returns the OpenCV type mapping supported.
+ Return the supported OpenCV types.
- :return: a dictionary containing the OpenCV type mapping supported.
+ :return: a list containing the supported OpenCV types.
.. versionadded:: 2.3.0
"""
if self._ocvTypes is None:
- ctx = SparkContext._active_spark_context
- self._ocvTypes =
dict(ctx._jvm.org.apache.spark.ml.image.ImageSchema.javaOcvTypes())
- return self._ocvTypes
+ ctx = SparkContext.getOrCreate()
+ ocvTypeList =
ctx._jvm.org.apache.spark.ml.image.ImageSchema.javaOcvTypes()
+ self._ocvTypes = [self._OcvType(name=x.name(),
+ mode=x.mode(),
+ nChannels=x.nChannels(),
+ dataType=x.dataType(),
+
nptype=self._ocvToNumpyMap[x.dataType()])
+ for x in ocvTypeList]
+ return self._ocvTypes[:]
+
+
+ def ocvTypeByName(self, name):
+ """
+ Return the supported OpenCvType with matching name or raise error
if there is no matching type.
+
+ :param: str name: OpenCv type name; must be equal to name of one
of the supported types.
+ :return: OpenCvType with matching name.
+
+ """
+
+ if self._ocvTypesByName is None:
+ self._ocvTypesByName = {x.name: x for x in self.ocvTypes}
+ if name not in self._ocvTypesByName:
+ raise ValueError(
+ "Can not find matching OpenCvFormat for type = '%s';
supported formats are = %s" %
+ (name, str(self._ocvTypesByName.keys())))
+ return self._ocvTypesByName[name]
+
+ def ocvTypeByMode(self, mode):
+ """
+ Return the supported OpenCvType with matching mode or raise error
if there is no matching type.
+
+ :param: int mode: OpenCv type mode; must be equal to mode of one
of the supported types.
+ :return: OpenCvType with matching mode.
--- End diff --
`OpenCvType` -> `OcvType`?
---
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]