厦门大学计算机网络小组第三周技术记录

一.  项目进展:


1.利用cpp程序直接生成视频和转图片

2.添加CRC码进行循环校验

3.进行传输速率测试

三.  技术尝试:

尝试使用海明校验,后改为CRC校验。

代码展示:

以下是裁剪二维码代码:

#include <opencv2/opencv.hpp>
#include <iostream>
#include <cmath>

using namespace cv;
using namespace std;

// 计算两点之间的距离
double distance(Point2f pt1, Point2f pt2) {
    return sqrt(pow(pt2.x - pt1.x, 2) + pow(pt2.y - pt1.y, 2));
}

int* firstBlack(cv::Mat& image)
{
    int* p = new int[2];
    for (int i = 0; i < image.rows; ++i)
    {
        for (int j = 0; j < image.cols; ++j)
        {
            if (image.at<unsigned char>(i, j) <= 15)
            {
                p[0] = i;
                p[1] = j;
                return p;
            }
        }
    }
}
int widtht(int x, int y, cv::Mat& image)
{
    while (1)
    {
        ++x;
        if (image.at<unsigned char>(y, x) >= 15)
            break;
    }
    return x - 1;
}

int main() {
    // 读取手机拍摄的图片
    Mat original_image = imread("1_1.png");

    // 将原始图片转换为灰度图
    Mat gray_image;
    cvtColor(original_image, gray_image, COLOR_BGR2GRAY);

    // 使用边缘检测找到定位区域
    Mat edges;
    Canny(gray_image, edges, 50, 150);

    // 找到定位区域的轮廓
    vector<vector<Point>> contours;
    findContours(edges, contours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);

    // 初始化第一个和第三个定位区域的坐标
    Point2f first_locator, third_locator;
    int t = 0;
    // 遍历所有满足条件的定位区域,找到第一个和第三个定位区域
    for (size_t i = 0; i < contours.size(); ++i) {
        // 计算轮廓的面积
        double area = contourArea(contours[i]);

        // 计算轮廓的外接矩形
        Rect locator_rect = boundingRect(contours[i]);

        // 根据面积和高宽比筛选定位区
        if (area > 5000 && area < 20000 && (double)locator_rect.width / locator_rect.height >= 0.95 && (double)locator_rect.width / locator_rect.height <= 1.05) {
            // 计算当前定位区的中心点
            Point2f center(locator_rect.x + locator_rect.width / 2.0, locator_rect.y + locator_rect.height / 2.0);
            Mat cropped_image = original_image(locator_rect);
            imshow("Cropped Image " + to_string(i + 1), cropped_image);
            waitKey(0);
            // 更新第一个和第三个定位区的坐标
            cout << center.x << " " << center.y << endl;

            if (center.x < 600 & center.y < 600) {
                first_locator = center;
            }
            else if (center.x > 600 && center.y < 600) {
                third_locator = center; // 改成第三次找到的定位区的中心点
                    // 找到第一个和第三个定位区域后退出循环
            }

        }
    }

    // 检查是否找到了第一个和第三个定位区域
    if (first_locator != Point2f(0, 0) && third_locator != Point2f(0, 0)) {
        // 计算旋转角度,使第一个和第三个定位区的中心点的纵坐标相同
        double vertical_offset = third_locator.y - first_locator.y;
        cout << first_locator.x << "  " << first_locator.y << "  " << third_locator.x << "  " << third_locator.y << endl;
        // 计算旋转中心
        Point2f center(first_locator.x, first_locator.y + vertical_offset / 2.0); // 向上或向下移动一半的垂直偏移

        // 计算旋转角度
        double angle = atan2(third_locator.y - first_locator.y, third_locator.x - first_locator.x) * 180 / CV_PI;

        // 计算旋转矩阵
        Mat rot_mat = getRotationMatrix2D(center, angle, 1.0);

        // 旋转图像
        Mat rotated_image;
        warpAffine(original_image, rotated_image, rot_mat, original_image.size(), INTER_CUBIC);
        /*imshow("Rotated Image", rotated_image);*/
        // 将原始图片转换为灰度图
        Mat gray_image;
        cvtColor(rotated_image, gray_image, COLOR_BGR2GRAY);

        // 使用边缘检测找到定位区域
        Mat edges;
        Canny(gray_image, edges, 50, 150);

        // 找到定位区域的轮廓
        vector<vector<Point>> contours;
        findContours(edges, contours, RETR_EXTERNAL, CHAIN_APPROX_SIMPLE);

        // 初始化最大最小坐标
        int minX = INT_MAX, minY = INT_MAX;
        int maxX = 0, maxY = 0;


        // 遍历所有满足条件的定位区域,找到第一个和第三个定位区域
        for (size_t i = 0; i < contours.size(); ++i) {
            // 计算轮廓的面积
            double area = contourArea(contours[i]);

            // 计算轮廓的外接矩形
            Rect locator_rect = boundingRect(contours[i]);

            // 根据面积和高宽比筛选定位区
            if (area > 5000 && area < 20000 && (double)locator_rect.width / locator_rect.height >= 0.8 && (double)locator_rect.width / locator_rect.height <= 1.2) {


                /* Mat cropped_image = original_image(locator_rect);
                 imshow("Cropped Image " + to_string(i + 1), cropped_image);
                 waitKey(0);*/
                minX = min(minX, locator_rect.x);
                minY = min(minY, locator_rect.y);
                maxX = max(maxX, locator_rect.x + locator_rect.width);
                maxY = max(maxY, locator_rect.y + locator_rect.height);

            }
        }



        // 检查是否找到了有效的定位区域
        if (minX != INT_MAX && minY != INT_MAX && maxX != 0 && maxY != 0) {
            // 计算定位区域的宽度和高度
            int width = maxX - minX;
            int height = maxY - minY;

            // 裁剪图片
            if (width > 0 && height > 0) {
                Mat cropped_image = rotated_image(Rect(minX, minY, width, height));
                // 例如,假设要压缩为 10 * 10 大小的图像
                Mat resized_image;
                
                // 缩放图像
                //resize(cropped_image, resized_image, Size(new_width, new_height));

                // 显示裁剪的图像
                imshow("Cropped Image", cropped_image);
                // 保存裁剪的图像到文件
                imwrite("cropped_image2.jpg", cropped_image);
                waitKey(0);
            }
            else {
                cout << "Invalid width or height for cropping." << endl;
            }
        }
        else {
            cout << "No valid contour found." << endl;
        }
    }
    else {
        cout << "First and third locator not found." << endl;
    }

    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
智慧校园建设是在国家政策推动下,为深化教育改革、提升教育质量和管理效率而提出的重要项目。该项目旨在通过信息化手段,解决传统教育中存在的资源分散、管理混乱等问题,实现教育资源的高效利用和教学质量的全面提升。 目前,教育信息化虽取得一定进展,但面临“孤岛架构”的挑战,包括硬件资源无法共享、数据孤岛、应用孤岛等问题,导致资源浪费和管理效率低下。为此,智慧校园的建设目标聚焦于家校沟通便捷化、校园管理科学化、校园生活轻松化、课堂教学互动化和校园设施智能化,以提高教学效率和学生学习体验。 智慧校园的核心价值在于构建先进的网络教学平台和管理信息系统,实现教学资源的高效配置和利用,促进师生互动,提高管理效率,降低成本,构建健康高雅的生活环境。解决方案涵盖综合应用平台规划、系统架构设计、媒体发布、数字会议系统等,通过后台服务层、基础接入层和用户接入层的有机结合,实现智慧校园的全面功能。 智慧校园管理平台作为核心组成部分,提供模块化体系,包括公开课、直播、教学资源等23大应用,支持与第三方接口对接,实现多级管理。电教预约管理平台通过移动端APP或web后台简化预约流程,提高教室和会议室资源利用率,支持会议预订、审批、信息发布和环境管控。 教育录播系统和云平台支持教师制作和分享优质教学资源,进行在线组卷和评卷,同时提供学生应用,如高清视频录制、在线直播和互动交流,促进教学资源的共享和教育均衡化发展。这些系统的整合应用,将极大地推动教育信息化进程,实现教育资源的最大化利用和教育质量的全面提升。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值