Пример #1
0
# you may not use this file except in compliance with the License.          #
# You may obtain a copy of the License at                                   #
#                                                                           #
#    http://www.apache.org/licenses/LICENSE-2.0                             #
#                                                                           #
# Unless required by applicable law or agreed to in writing, software       #
# distributed under the License is distributed on an "AS IS" BASIS,         #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  #
# See the License for the specific language governing permissions and       #
# limitations under the License.                                            #
#############################################################################

import mpf_component_api as mpf

# logger = mpf.configure_logging('python-test.log', __name__ == '__main__')
logger = mpf.configure_logging('python-test.log', True)


class TestComponent(object):
    detection_type = 'TEST DETECTION TYPE'

    def __init__(self):
        logger.info('Creating instance of TestComponent')

    @staticmethod  # Make sure executor can call static methods
    def get_detections_from_image(image_job):
        logger.info('[%s] Received image job: %s', image_job.job_name,
                    image_job)
        if image_job.feed_forward_location is not None:
            yield image_job.feed_forward_location
            return
# Unless required by applicable law or agreed to in writing, software       #
# distributed under the License is distributed on an "AS IS" BASIS,         #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  #
# See the License for the specific language governing permissions and       #
# limitations under the License.                                            #
#############################################################################

from __future__ import division, print_function

import pkg_resources
import os

import mpf_component_api as mpf
import mpf_component_util as mpf_util

logger = mpf.configure_logging('python-ocv-test.log', __name__ == '__main__')


class OcvComponent(mpf_util.ImageReaderMixin, mpf_util.VideoCaptureMixin,
                   object):
    detection_type = 'TEST OCV DETECTION TYPE'

    @staticmethod
    def get_detections_from_image_reader(image_job, image_reader):
        logger.info('[%s] Received image job: %s', image_job.job_name,
                    image_job)
        model = get_model(image_job)  # A real component would use the model.

        img = image_reader.get_image()

        height, width, _ = img.shape
Пример #3
0
# distributed under the License is distributed on an "AS IS" BASIS,         #
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  #
# See the License for the specific language governing permissions and       #
# limitations under the License.                                            #
#############################################################################

from io import BytesIO
import os
import subprocess
from typing import Optional

from pydub.audio_segment import fix_wav_headers

import mpf_component_api as mpf

logger = mpf.configure_logging('audio-ripper.log', __name__ == '__main__')


def transcode_to_wav(filepath: str,
                     start_time: float = 0,
                     stop_time: Optional[float] = None) -> bytes:
    """
    Transcodes the audio contained in filepath (can be an audio or video file)
    from from start_time to stop_time to WAVE format using ffmpeg, and returns it as a byte string (read from a BytesIO object).

    :param filepath: The path to the file (job.data_uri).
    :param start_time: The time (in milliseconds) associated with the beginning of audio segment. Default 0.
    :param stop_time: The time (in milliseconds) associated with the end of the audio segment. To go to the end of the file, pass None. Default None.
    """
    logger.info(
        ('Reading and transcoding audio in {filepath:s} to WAVE format.'