# openCVPracticalExercise学习笔记02

8 篇文章 0 订阅

## 10使用Hu矩进行形状匹配

Hu矩（或者更确切地说是Hu矩不变量）是使用对图像变换不变的中心矩计算的一组7个变量。事实证明，前6个矩不变量对于平移，缩放，旋转和映射都是不变的。而第7个矩会因为图像映射而改变。
OpenCV中，我们HuMoments()用来计算输入图像中的Hu矩。

 1 2 3  _,im = cv2.threshold(im, 128, 255, cv2.THRESH_BINARY) moment = cv2.moments(im) huMoments = cv2.HuMoments(moment) 

 1  m2 = cv2.matchShapes(im1,im2,cv2.CONTOURS_MATCH_I2,0) 

## 11基于OpenCV的二维码扫描器

 1 2  qrDecoder = cv2.QRCodeDetector() data,bbox,rectifiedImage = qrDecoder.detectAndDecode(inputImage) 

## 12使用深度学习和OpenCV进行手部关键点检测

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20  inpBlob = cv2.dnn.blobFromImage(frame, 1.0 / 255, (inWidth, inHeight), (0, 0, 0), swapRB=False, crop=False) net.setInput(inpBlob) output = net.forward() print("time taken by network : {:.3f}".format(time.time() - t)) points = [] for i in range(nPoints): probMap = output[0, i, :, :] probMap = cv2.resize(probMap, (frameWidth, frameHeight)) minVal, prob, minLoc, point = cv2.minMaxLoc(probMap) if prob > threshold : cv2.circle(frameCopy, (int(point[0]), int(point[1])), 8, (0, 255, 255), thickness=-1, lineType=cv2.FILLED) points.append((int(point[0]), int(point[1]))) else : points.append(None) 

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20  # For each frame, extract the bounding box and mask for each detected object def postprocess(boxes, masks): numClasses = masks.shape[1] numDetections = boxes.shape[2] frameH = frame.shape[0] frameW = frame.shape[1] for i in range(numDetections): box = boxes[0, 0, i] mask = masks[i] score = box[2] if score > confThreshold: classId = int(box[1]) # Extract the bounding box left top right bottom = xxx classMask = mask[classId] drawBox(frame, classId, score, left, top, right, bottom, classMask) 

## 14使用OpenCV实现单目标跟踪

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15  bbox = cv2.selectROI(frame, False) ok = tracker.init(frame, bbox) while True: ok, frame = video.read() if not ok: break ok, bbox = tracker.update(frame) if ok: # Tracking success p1 = (int(bbox[0]), int(bbox[1])) p2 = (int(bbox[0] + bbox[2]), int(bbox[1] + bbox[3])) cv2.rectangle(frame, p1, p2, (255,0,0), 2, 1) 

## 16使用OpenCV实现多目标跟踪Video

 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18  # Create MultiTracker object multiTracker = cv2.MultiTracker_create() for bbox in bboxes: multiTracker.add(createTrackerByName(trackerType), frame, bbox) while cap.isOpened(): success, frame = cap.read() if not success: break # get updated location of objects in subsequent frames success, boxes = multiTracker.update(frame) # draw tracked objects for i, newbox in enumerate(boxes): p1 = (int(newbox[0]), int(newbox[1])) p2 = (int(newbox[0] + newbox[2]), int(newbox[1] + newbox[3])) cv2.rectangle(frame, p1, p2, colors[i], 2, 1) 

## 18Opencv中的单应性矩阵Homography(略)

Homography的应用-全景拼接

 1 2 3 4 5  # Calculate Homography h, status = cv2.findHomography(pts_src, pts_dst) # Warp source image to destination based on homography im_out = cv2.warpPerspective(im_src, h, (im_dst.shape[1],im_dst.shape[0])) 

## 19使用OpenCV实现基于特征的图像对齐

OpenCV的图像对齐
2.1 基于特征的图像对齐的步骤

Step1读图

Step2寻找特征点

Step3 特征点匹配

Step4 计算Homography

https://www.cnblogs.com/xingshansi/p/6763668.html
https://blog.csdn.net/zinnc/article/details/52319716
Step5 图像映射

• 0
点赞
• 0
评论
• 0
收藏
• 一键三连
• 扫一扫，分享海报

09-21 9万+
04-08 100万+
07-05 2万+
04-02
04-10 65万+
04-07 6万+
07-25 3740
06-16 1万+
04-05 5974
04-06 1万+