def _write_openjp2(self, img_array, verbose=False):
if img_array.ndim == <NUM_LIT:2>:<EOL><INDENT>numrows, numcols = img_array.shape<EOL>img_array = img_array.reshape(numrows, numcols, <NUM_LIT:1>)<EOL><DEDENT>self._populate_comptparms(img_array)<EOL>with ExitStack() as stack:<EOL><INDENT>image = opj2.image_create(self._comptparms, self._colorspace)<EOL>stack.callback(opj2.image_destroy, image)<EOL>self._populate_image_struct(image, img_array)<EOL>codec = opj2.create_compress(self._cparams.codec_fmt)<EOL>stack.callback(opj2.destroy_codec, codec)<EOL>if self._verbose or verbose:<EOL><INDENT>info_handler = _INFO_CALLBACK<EOL><DEDENT>else:<EOL><INDENT>info_handler = None<EOL><DEDENT>opj2.set_info_handler(codec, info_handler)<EOL>opj2.set_warning_handler(codec, _WARNING_CALLBACK)<EOL>opj2.set_error_handler(codec, _ERROR_CALLBACK)<EOL>opj2.setup_encoder(codec, self._cparams, image)<EOL>strm = opj2.stream_create_default_file_stream(self.filename,<EOL>False)<EOL>stack.callback(opj2.stream_destroy, strm)<EOL>opj2.start_compress(codec, image, strm)<EOL>opj2.encode(codec, strm)<EOL>opj2.end_compress(codec, strm)<EOL><DEDENT>self.parse()<EOL>
Write JPEG 2000 file using OpenJPEG 2.x interface.