1. Trang chủ
  2. » Tất cả

(Đồ án hcmute) ứng dụng thuật toán nén ảnh bpg vào trong chuông cửa iot

105 4 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Định dạng
Số trang 105
Dung lượng 4,86 MB

Nội dung

BỘ GIÁO DỤC VÀ ĐÀO TẠO TRƯỜNG ĐẠI HỌC SƯ PHẠM KỸ THUẬT THÀNH PHỐ HỒ CHÍ MINH ĐỒ ÁN TỐT NGHIỆP NGÀNH CƠNG NGHỆ KỸ THUẬT MÁY TÍNH ỨNG DỤNG THUẬT TỐN NÉN ẢNH BPG VÀO TRONG CHNG CỬA IOT GVHD: VÕ MINH HUÂN SVTH: NGUYỄN PHẠM THANH HOÀNG MSSV: 13119085 SKL 0 7 Tp Hồ Chí Minh, tháng 01/2020 an TRƯỜNG ĐẠI HỌC SƯ PHẠM KỸ THUẬT TP HỒ CHÍ MINH KHOA ĐÀO TẠO CHẤT LƯỢNG CAO ĐỒ ÁN TỐT NGHIỆP ỨNG DỤNG THUẬT TỐN NÉN ẢNH BPG VÀO TRONG CHNG CỬA IOT SVTH: NGUYỄN PHẠM THANH HỒNG MSSV: 13119085 KHỐ: 2013-2017 NGÀNH: CƠNG NGHỆ KỸ THUẬT MÁY TÍNH GVHD: PGS TS VÕ MINH HUÂN TP HỒ CHÍ MINH, THÁNG NĂM 2020 an CỘNG HÒA XÃ HỘI CHỦ NGHĨA VIỆT NAM Độc lập – Tự – Hạnh phúc *** -TP Hồ Chí Minh, ngày 30 tháng 12 năm 2019 NHIỆM VỤ ĐỒ ÁN TỐT NGHIỆP Họ tên sinh viên: Nguyễn Phạm Thanh Hồng Ngành: Cơng nghệ kỹ thuật máy tính Lớp: 13119CL2 Giảng viên hướng dẫn: PGS TS Võ Minh Huân Ngày nhận đề tài: 10/9/2019 MSSV: 13119085 ĐT: 0909437522 Ngày nộp đề tài: 30/12/2019 Tên đề tài: Ứng dụng thuật toán nén ảnh vào chuông cửa IOT Nội dung thực đề tài: Thiết kế thuật toán nén ảnh ứng dụng Smart IOT Doorbell Sản phẩm: Ứng dụng thuật toán để nén ảnh môi trường IOT giữ nguyên chất lượng hình ảnh TRƯỞNG NGÀNH GIẢNG VIÊN HƯỚNG DẪN i an CỘNG HÒA XÃ HỘI CHỦ NGHĨA VIỆT NAM Độc lập – Tự – Hạnh phúc *** -TP Hồ Chí Minh, ngày 30 tháng 12 năm 2019 PHIẾU NHẬN XÉT CỦA GIÁO VIÊN HƯỚNG DẪN Họ tên Sinh viên: Nguyễn Phạm Thanh Hoàng MSSV: 13119085 Ngành: Cơng nghệ kỹ thuật máy tính Tên đề tài: Ứng dụng thuật toán nén ảnh vào chuông cửa IOT Họ tên Giáo viên hướng dẫn: PGS TS Võ Minh Huân NHẬN XÉT 1.Về nội dung đề tài & khối lượng thực hiện: Ưu điểm: Khuyết điểm: Đề nghị cho bảo vệ hay không? Đánh giá loại: Điểm: ……… (Bằng chữ: ) GIẢNG VIÊN HƯỚNG DẪN ii an CỘNG HÒA XÃ HỘI CHỦ NGHĨA VIỆT NAM Độc lập – Tự – Hạnh phúc *** -TP Hồ Chí Minh, ngày 30 tháng 12 năm 2019 PHIẾU NHẬN XÉT CỦA GIÁO VIÊN PHẢN BIỆN Họ tên Sinh viên: Nguyễn Phạm Thanh Hồng MSSV: 13119085 Ngành: Cơng nghệ kỹ thuật máy tính Tên đề tài: Ứng dụng thuật toán nén ảnh vào chuông cửa IOT Họ tên Giáo viên phản biện: NHẬN XÉT Về nội dung đề tài & khối lượng thực hiện: Ưu điểm: Khuyết điểm: Đề nghị cho bảo vệ hay không? Đánh giá loại: Điểm: ………… (Bằng chữ: ) GIẢNG VIÊN PHẢN BIỆN iii an LỜI CẢM ƠN Trong thời gian làm đồ án tốt môn học, em nhận nhiều sự giúp đỡ, đóng góp ý kiến và bảo nhiệt tình thầy cơ, gia đình và bạn bè Nhóm em xin gửi lời cảm ơn chân thành đến GVHD Võ Minh Huân, giảng viên Khoa Điện – Điện Tử - Trường ĐH Sư Phạm Kỹ Thuật TP.HCM, người tận tình hướng dẫn, bảo em suốt trình làm đồ án Nhóm em xin chân thành cảm ơn thầy cô giáo trường ĐH Sư Phạm Kỹ Thuật TP.HCM nói chung, thầy Khoa Chất Lượng Cao nói riêng dạy dỗ cho em kiến thức môn đại cương mơn chun ngành, giúp em có sở lý thuyết vững vàng và tạo điều kiện giúp đỡ em suốt trình học tập Cuối cùng, em xin chân thành cảm ơn gia đình và bạn bè, tạo điều kiện, quan tâm, giúp đỡ, động viên em suốt trình học tập và hoàn thành đồ án môn học Sinh viên thực Nguyễn Phạm Thanh Hồng iv an LỜI MỞ ĐẦU Cơng nghệ và khoa học ngày càng phát triển cách nhanh chóng, mục đích cuối là đem lại cho người sự thuận tiện đến mức tối đa sống hàng ngày Điều này không ngoại lệ nói đến q trình nén ảnh Các nhà phát triển cố gắng không ngừng để cải thiện trình nén ảnh nhằm tối ưu hiệu lưu trữ và truyền tải Với sự đời chuẩn nén video H.265 hay gọi High Efficiency Video Coding – HEVC định dạng ảnh PBG giúp tối ưu hố q trình hết mức Sự bùng nổ Internet of Things (IoT) năm gần tác động mạnh mẽ đến xu hướng công nghệ xã hội Ứng dụng rộng khắp tiện ích tuyệt vời mà IoT mang lại tạo nên xu hướng sống Nhằm bắt kịp xu hướng đó, em định chọn chuẩn nén ảnh BPG chuông cửa IOT làm đối tượng nghiên cứu v an MỤC LỤC TRANG PHỤ BÌA Trang NHIỆM VỤ ĐỒ ÁN TỐT NGHIỆP i PHIẾU NHẬN XÉT CỦA GIÁO VIÊN HƯỚNG DẪN ii PHIẾU NHẬN XÉT CỦA GIÁO VIÊN PHẢN BIỆN iii LỜI CẢM ƠN iv LỜI MỞ ĐẦU v MỤC LỤC vi DANH MỤC CÁC HÌNH ẢNH, BIỂU ĐỒ ix DANH MỤC CÁC BẢNG BIỂU xi Chương TỔNG QUAN 1.1 ĐẶT VẤN ĐỀ 1.2 MỤC TIÊU 1.3 NỘI DUNG NGHIÊN CỨU 1.4 GIỚI HẠN 1.5 BỐ CỤC Chương CƠ SỞ LÝ THUYẾT 2.1 TỔNG QUAN VỀ ĐỊNH DẠNG HÌNH ẢNH 2.1.1 Giới thiệu hình ảnh số 2.1.2 Giới thiệu định dạng hình ảnh 2.1.3 Các phương thức nén ảnh 14 2.1.3.1 Khái niệm nén ảnh 14 2.1.3.2 Tìm hiểu HEVC 16 2.2 KHỐI PHẦN CỨNG VỀ HỆ THỐNG CHUÔNG CỬA THÔNG MINH 19 2.2.1 KIT Raspberry Pi Zero W 20 2.2.2 Mạch Raspberry Pi Camera V2 5MP 21 2.2.2.1 Giới thiệu chung 22 2.2.2.2 Thông số kỹ thuật 23 2.3 PHẦN MỀM VÀ DỊCH VỤ SỬ DỤNG 23 2.3.1 Ngơn ngữ lập trình Python 23 vi an 2.3.1.1 Giới thiệu 23 2.3.1.2 Thư viện bpg 24 2.3.2 Dịch vụ GMAIL Google 25 2.3.3 Phần mềm thiết kế phần cứng Altium 26 Chương THIẾT KẾ HỆ THỐNG 27 3.1 CHUẨN ẢNH ĐỊNH DẠNG MỚI BPG 27 3.1.1 Giới thiệu định dạng ảnh BPG 27 3.1.2 Thuật tốn nén BPG đơn giản hóa 28 3.1.3 Kết thực tế nén ảnh BPG 33 3.2 LỰA CHỌN PHƯƠNG PHÁP THIẾT KẾ 36 3.3 THIẾT KẾ VÀ TÍNH TỐN HỆ THỐNG 38 3.3.1 Sơ đồ khối hệ thống 38 3.3.2 Khối phần cứng hệ thống 39 3.3.2.1 Khối điều khiển trung tâm 39 3.3.2.2 CAMERA 41 3.3.2.3 Khối thông báo LED 42 3.3.2.4 Khối nút nhấn 44 3.3.2.5 Khối nguồn 44 3.3.3 Khối dịch vụ Gmail Google 45 3.3.4 Khối xử lý ứng dụng android 48 3.4 LƯU ĐỒ GIẢI THUẬT 50 3.4.1 Xử lý khối phần cứng hệ thống 50 3.4.1.1 Quy trình hoạt động khối phần cứng 50 3.4.1.2 Quá trình xử lý 52 3.4.2 Giải mã hình ảnh ứng dụng android 55 3.4.2.1 Quy trình lấy liệu từ Gmail Cloud 55 3.4.2.2 Xử lý giải nén hình ảnh ứng dụng android 57 Chương KẾT QUẢ, NHẬN XÉT, ĐÁNH GIÁ 60 4.1 KẾT QUẢ 60 4.1.1 Kết so sánh hình ảnh dạng BPG 60 4.1.2 Kết sản phẩm hoàn thiện 61 vii an 4.1.2.1 Kết sản phẩm phần cứng 61 4.1.2.2 Kết ứng dụng android SMART DOORBELL 64 4.2 NHẬN XÉT VÀ ĐÁNH GIÁ 66 4.2.1 Kết 66 4.2.2 Ưu điểm 66 4.2.3 Nhược điểm 67 Chương KẾT LUẬN VÀ HUỚNG PHÁT TRIỂN 68 5.1 KẾT LUẬN 68 5.2 HƯỚNG PHÁT TRIỂN 68 TÀI LIỆU THAM KHẢO 70 PHỤ LỤC 71 viii an def compare_images(imageA, imageB, title): # compute the mean squared error and structural similarity # index for the images m = mse(imageA, imageB) s = ssim(imageA, imageB) # setup the figure fig = plt.figure(title) plt.suptitle("MSE: %.2f, SSIM: %.2f" % (m, s)) # show first image ax = fig.add_subplot(1, 2, 1) plt.imshow(imageA, cmap = plt.cm.gray) plt.axis("off") # show the second image ax = fig.add_subplot(1, 2, 2) plt.imshow(imageB, cmap = plt.cm.gray) plt.axis("off") # show the images plt.show() original = cv2.imread("images/jp_gates_original.png") contrast = cv2.imread("images/jp_gates_contrast.png") shopped = cv2.imread("images/jp_gates_photoshopped.png") original = cv2.cvtColor(original, cv2.COLOR_BGR2GRAY) contrast = cv2.cvtColor(contrast, cv2.COLOR_BGR2GRAY) shopped = cv2.cvtColor(shopped, cv2.COLOR_BGR2GRAY) 78 an # initialize the figure fig = plt.figure("Images") images = ("Original", original), ("Contrast", contrast), ("Photoshopped", shopped) for (i, (name, image)) in enumerate(images): # show the image ax = fig.add_subplot(1, 3, i + 1) ax.set_title(name) plt.imshow(image, cmap = plt.cm.gray) plt.axis("off") plt.show() # compare the images compare_images(original, original, "Original vs Original") compare_images(original, contrast, "Original vs Contrast") compare_images(original, shopped, "Original vs Photoshopped") CHƯƠNG TRÌNH CHÍNH import os import glob import picamera import RPi.GPIO as GPIO import smtplib from time import sleep import requests from datetime import datetime 79 an from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.mime.base import MIMEBase from email import encoders sender = 'penvpsiot@gmail.com' password = '231114@ayeHu' receiver = 'n.hoang7895@gmail.com' DIR = './Visitors/' prefix = 'image' old_status = GPIO.setwarnings(False) GPIO.setmode(GPIO.BOARD) GPIO.setup(15, GPIO.IN) # button input GPIO.setup(16, GPIO.OUT) # output buzzer GPIO.output(16, 0) def led_status(pin,value) GPIO.output(pin, value) sleep(1) GPIO.output(pin,~value) def check_internet(): 80 an url='http://www.google.com/' timeout=5 try: _ = requests.get(url, timeout=timeout) return True except requests.ConnectionError: print("İnternet bağlantısı yok.") return False def send_mail(filename): msg = MIMEMultipart() msg['From'] = sender msg['To'] = receiver msg['Subject'] = '[SMART_DOORBEEL] Alert!!! There are some Visitors!' body = 'There are some visitors let check the images in attachment! \n Please open SMART DOORBELL mobile application to see images and timelines.\n' msg.attach(MIMEText(body, 'plain')) attachment = open(filename, 'rb') part = MIMEBase('application', 'octet-stream') part.set_payload((attachment).read()) encoders.encode_base64(part) #=get time ========== 81 an now = datetime.now() dt_string = now.strftime("_%Y/%m/%d_%H%M%S") part.add_header('Content-Disposition', 'attachment; filename= %s' % ('visitor'+dt_string+'.bpg')) msg.attach(part) server = smtplib.SMTP('smtp.gmail.com', 587) server.starttls() server.login(sender, password) text = msg.as_string() server.sendmail(sender, receiver, text) server.quit def capture_img(): print ("Capturing") if not os.path.exists(DIR): os.makedirs(DIR) files = sorted(glob.glob(os.path.join(DIR, prefix + '[0-9][0-9][0-9].jpg'))) filename = os.path.join(DIR, prefix + '.jpg') with picamera.PiCamera() as camera: camera.resolution = (640, 360) pic = camera.capture(filename) os.system('bpgenc -m -o /Visitors/output.bpg /Visitors/image.jpg') filename = os.path.join(DIR, 'output.bpg') 82 an print ("Link send mail file: ",filename) send_mail(filename) if check_internet() == True: while True: num = GPIO.input(15) #num=int(input("Press button by press number:")) if old_status == num : #print ("Button donot press") continue else: GPIO.output(16, 1) old_status == num print ("Waiting", num) sleep(0.5) num = GPIO.input(15) if num == 0: print ("Captured->Sending", num) GPIO.output(16, 0) capture_img() GPIO.output(16, 0) else : 83 an print ("No internet connection ! Do some action") ỨNG DỤNG ANDROID public void onClick(View v) { if (!isGooglePlayServicesAvailable()) { acquireGooglePlayServices(); } else { chooseAccount(); } } }); } protected void onActivityResult(int requestCode, int resultCode, Intent data) { super.onActivityResult(requestCode, resultCode, data); switch (requestCode) { case REQUEST_GOOGLE_PLAY_SERVICES: if (resultCode != RESULT_OK) { AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this); builder.setMessage(R.string.this_app_requires_google_play_services); 84 an builder.setPositiveButton(getString(android.R.string.cancel), new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); ActivityCompat.finishAffinity(MainActivity.this); } }); AlertDialog dialog = builder.create(); dialog.show(); } else { chooseAccount(); } break; case REQUEST_ACCOUNT_PICKER: if (resultCode == RESULT_OK && data != null &&) 85 an data.getExtras() != null) { String accountName = data.getStringExtra(AccountManager.KEY_ACCOUNT_N AME); if (accountName != null) { SharedPreferences.Editor editor = sharedPref.edit(); editor.putString(PREF_ACCOUNT_NAME, accountName); editor.apply(); mCredential.setSelectedAccountName(accountName); startActivity(new Intent(MainActivity.this, InboxActivity.class)); ActivityCompat.finishAffinity(MainActivity.this); } } break; case REQUEST_AUTHORIZATION: if (resultCode == RESULT_OK) { chooseAccount(); 86 an } break; } } void showGooglePlayServicesAvailabilityErrorDialog( final int connectionStatusCode) { GoogleApiAvailability apiAvailability = GoogleApiAvailability.getInstance(); Dialog dialog = apiAvailability.getErrorDialog( MainActivity.this, connectionStatusCode, REQUEST_GOOGLE_PLAY_SERVICES); dialog.show(); } } GIẢI MÃ BPG public class Decoder extends Activity { private ImageView m_image; private Button m_button; private Spinner m_spinner; 87 an //Load library static { System.loadLibrary("bpg_decoder"); }; public static byte[] toByteArray(InputStream input) throws IOException { byte[] buffer = new byte[1024]; int bytesRead; ByteArrayOutputStream output = new ByteArrayOutputStream(); while ((bytesRead = input.read(buffer)) != -1) { output.write(buffer, 0, bytesRead); } return output.toByteArray(); } public Bitmap getDecodedBitmap(int resourceId){ Bitmap bm = null; InputStream is = getResources().openRawResource(resourceId); try{ 88 an byte[] byteArray = toByteArray(is); byte[] decBuffer = null; int decBufferSize = 0; decBuffer = DecoderWrapper.decodeBuffer(byteArray, byteArray.length); decBufferSize = decBuffer.length; if(decBuffer != null){ bm = BitmapFactory.decodeByteArray(decBuffer, 0, decBufferSize); } } catch(IOException ex){ Log.i("MainActivity", "Failed to convert image to byte array"); } return bm; } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // setContentView(R.layout.bpg_decoder); addListenerOnButton(); 89 an } // @Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present // getMenuInflater().inflate(R.menu.main, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { // Handle action bar item clicks here The action bar will // automatically handle clicks on the Home/Up button, so long // as you specify a parent activity in AndroidManifest.xml int id = item.getItemId(); if (id == R.string.action_settings){ return true; } return super.onOptionsItemSelected(item); } public void addListenerOnButton() 90 an { // m_image = (ImageView) findViewById(R.id.imageView1); } } 91 an S an K L 0 ... đề tài: Ứng dụng thuật toán nén ảnh vào chuông cửa IOT Nội dung thực đề tài: Thiết kế thuật toán nén ảnh ứng dụng Smart IOT Doorbell Sản phẩm: Ứng dụng thuật tốn để nén ảnh mơi trường IOT giữ...TRƯỜNG ĐẠI HỌC SƯ PHẠM KỸ THUẬT TP HỒ CHÍ MINH KHOA ĐÀO TẠO CHẤT LƯỢNG CAO ĐỒ ÁN TỐT NGHIỆP ỨNG DỤNG THUẬT TOÁN NÉN ẢNH BPG VÀO TRONG CHNG CỬA IOT SVTH: NGUYỄN PHẠM THANH... phải vận dụng phương thức nén ảnh theo định dạng BPG để áp dụng tạo hệ thống vận dụng vào đời sống Riêng hình ảnh phải xử lý hình ảnh đầu vào từ camera Ứng dụng ảnh định dạng BPG ứng dụng vào

Ngày đăng: 02/02/2023, 09:35

TÀI LIỆU CÙNG NGƯỜI DÙNG

TÀI LIỆU LIÊN QUAN