官术网_书友最值得收藏!

Running the app – the main() function routine

To run our app, we will need to execute the main() function routine. The following steps show us the execution of main() routine: 

  1. The function first accesses the webcam with the VideoCapture method by passing 0 as an argument, which is a reference to the default webcam. If it can not access the webcam, the app will be terminated:
import cv2 as cv
from feature_matching import FeatureMatching

def main():
capture = cv.VideoCapture(0)
assert capture.isOpened(), "Cannot connect to camera"
  1. Then, the desired frame size and frame per second of the video stream is set. The following snippet shows the code for setting the frame size and frame per second of the video:
 capture.set(cv.CAP_PROP_FPS, 10)
capture.set(cv.CAP_PROP_FRAME_WIDTH, 640)
capture.set(cv.CAP_PROP_FRAME_HEIGHT, 480)
  1. Next, an instance of the FeatureMatching class is initialized with a path to a template (or training) file that depicts the object of interest. The following code shows the FeatureMatching class:
matching = FeatureMatching(train_image='train.png')
  1. After that, to process the frames from the camera, we create an iterator from the capture.read function, which will terminate when the function fails to return frame ((False,None)). This can be seen in the following code block:
    for success, frame in iter(capture.read, (False, None)):
cv.imshow("frame", frame)
match_succsess, img_warped, img_flann = matching.match(frame)

In the previous code block, the FeatureMatching.match method processes the BGR image (capture.read returns frame in BGR format)If the object is detected in the current frame, the match method will report match_success=True and return the warped image as well as the image that illustrates the matches—img_flann.

Let's move on and display the results in which our match method will return.

主站蜘蛛池模板: 大城县| 杭锦后旗| 墨脱县| 榆中县| 凤庆县| 阆中市| 兰溪市| 阿拉善右旗| 朝阳县| 楚雄市| 尚志市| 蒲城县| 永春县| 伽师县| 原平市| 论坛| 茶陵县| 康平县| 江达县| 桓仁| 望奎县| 腾冲县| 岢岚县| 高邑县| 桑植县| 延长县| 肃南| 随州市| 楚雄市| 定西市| 科技| 砀山县| 梓潼县| 临潭县| 南丹县| 从江县| 株洲市| 永城市| 阿瓦提县| 乌鲁木齐市| 定州市|