java的Intersect用法_Java Rectangle2D.intersect方法代码示例

import java.awt.geom.Rectangle2D; //导入方法依赖的package包/类

/**

* Damages the area surrounding the caret to cause

* it to be repainted in a new location. If paint()

* is reimplemented, this method should also be

* reimplemented. This method should update the

* caret bounds (x, y, width, and height).

*

* @param r the current location of the caret

* @see #paint

*/

@Override

protected synchronized void damage(final Rectangle r) {

if (r == null || fPainting) return;

x = r.x - 4;

y = r.y;

width = 10;

height = r.height;

// Don't damage the border area. We can't paint a partial border, so get the

// intersection of the caret rectangle and the component less the border, if any.

final Rectangle caretRect = new Rectangle(x, y, width, height);

final Border border = getComponent().getBorder();

if (border != null) {

final Rectangle alloc = getComponent().getBounds();

alloc.x = alloc.y = 0;

final Insets borderInsets = border.getBorderInsets(getComponent());

alloc.x += borderInsets.left;

alloc.y += borderInsets.top;

alloc.width -= borderInsets.left + borderInsets.right;

alloc.height -= borderInsets.top + borderInsets.bottom;

Rectangle2D.intersect(caretRect, alloc, caretRect);

}

x = caretRect.x;

y = caretRect.y;

width = Math.max(caretRect.width, 1);

height = Math.max(caretRect.height, 1);

repaint();

}

def detect_objects(self,frame,number): frame_count = 0 process_every = 2 # 每2帧处理1帧 frame_count +=2 if frame_count % process_every == 0: # 保存原始帧 original_frame = frame.copy() # 降采样 small_frame = cv2.resize(frame, (640, 480)) # small_frame = cv2.resize(frame, (1920, 1080)) # 检测 results = self.model(small_frame, conf=self.conf, iou=self.iou) annotated_frame = results[0].plot() detections = [] wheel_hub_info = [] # 存储轮毂信息 for result in results: for box in result.names: # class_id = int(box.cls) # class_name = self.model.names[class_id] # confidence = float(box.conf) #x, y, w, h = box.xywh[0].tolist() x,y,w,h,r = result.obb.xywhr # center-x, center-y, width, height, angle (radians) xy,xy,xy,xy = result.obb.xyxyxyxy # polygon format with 4-points class_name = [result.names[cls.item()] for cls in result.obb.cls.int()] # class name of each box confidence = result.obb.conf # confidence score of each box # 如果是轮毂别(根据您的模型别定义) if class_name == "xiaoxiaozipeijian": # 替换为实际的轮毂别名称 # 转换为整数坐标 x1 = int(x - w / 2) y1 = int(y - h / 2) x2 = int(x + w / 2) y2 = int(y + h / 2) # 确保坐标在图像范围内 x1 = max(0, x1) y1 = max(0, y1) x2 = min(frame.shape[1], x2) y2 = min(frame.shape[0], y2) # 提取轮毂ROI区域 wheel_roi = original_frame[y1:y2, x1:x2] # 分析轮毂颜色 if wheel_roi.size > 0: # 确保区域有效 primary_color, color_name = self.analyze_wheel_hub_color(wheel_roi) # 在图像上绘制颜色信息 cv2.rectangle(annotated_frame, (x1, y1), (x2, y2), (0, 255, 0), 2) cv2.putText(annotated_frame, f"Color: {color_name}", (x1, y1 - 10), cv2.FONT_HERSHEY_SIMPLEX, 0.5, (0, 255, 0), 2) # 存储轮毂信息 wheel_hub_info.append({ "position": (x, y), "size": (w, h), "color": primary_color.tolist(), "color_name": color_name, "confidence": confidence }) detections.append((class_name, confidence, x, y)) # 发送包含轮毂信息的结果 self.frame_received_new.emit( cv2.cvtColor(original_frame, cv2.COLOR_BGR2RGB), cv2.cvtColor(annotated_frame, cv2.COLOR_BGR2RGB), detections, number+1, wheel_hub_info # 添加轮毂信息 ) #return frame 对于obb检测,这部分如何修改
最新发布
11-16
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值