23d15da98ec99cf2b848f192c0763b55e1dbfc04,berrynet/client/camera.py,,main,#,82

Before Change



        while True:
            status, im = capture.read()
            if (status is False):
                logger.warn("ERROR: Failure happened when reading frame")

            counter += 1
            if counter == interval:
                logger.debug("Drop frames: {}".format(counter-1))
                counter = 0

After Change


            //    True if a stream is dead afterward. So you can not use
            //    the capture return value (capture status) to determine
            //    whether a stream is alive or not.
            if (status is True):
                counter += 1
                if counter == interval:
                    logger.debug("Drop frames: {}".format(counter-1))
                    counter = 0

                    // Open a window and display the ready-to-send frame.
                    // This is useful for development and debugging.
                    if args["display"]:
                        cv2.imshow("Frame", im)
                        cv2.waitKey(1)

                    t = datetime.now()
                    retval, jpg_bytes = cv2.imencode(".jpg", im)
                    mqtt_payload = payload.serialize_jpg(jpg_bytes)
                    comm.send("berrynet/data/rgbimage", mqtt_payload)
                    logger.debug("send: {} ms".format(duration(t)))
                else:
                    pass
            else:
                fail_counter += 1
                logger.critical("ERROR: Failure //{} happened when reading frame".format(fail_counter))

                // Re-create capture.
                capture.release()
                logger.critical("Re-create a capture and reconnect to {} after 5s".format(stream_source))
                time.sleep(5)
                capture = cv2.VideoCapture(stream_source)
    elif args["mode"] == "file":
        // Prepare MQTT payload
        im = cv2.imread(args["filepath"])
        retval, jpg_bytes = cv2.imencode(".jpg", im)
Italian Trulli
In pattern: SUPERPATTERN

Frequency: 3

Non-data size: 3

Instances


Project Name: DT42/BerryNet
Commit Name: 23d15da98ec99cf2b848f192c0763b55e1dbfc04
Time: 2020-02-15
Author: bofu@dt42.io
File Name: berrynet/client/camera.py
Class Name:
Method Name: main


Project Name: pantsbuild/pants
Commit Name: cff740c5b4077bb29e4e687849b2d617a20d62f7
Time: 2014-06-17
Author: benjy@foursquare.com
File Name: src/python/pants/backend/python/tasks/python_run.py
Class Name: PythonRun
Method Name: execute


Project Name: vatlab/SoS
Commit Name: 2c9b35fd80328c4c6270ef03149b7ffc17619860
Time: 2016-10-10
Author: ben.bog@gmail.com
File Name: pysos/dag.py
Class Name: SoS_DAG
Method Name: find_executable