emgucv_基礎畫圖著色筆記_row-major_vs_column-major




簡易視窗配置


如何鎖住  imageBox 物件的 滾輪自動放大縮小功能

以及 右鍵  作效果等功能

右側  --->  找到  Functional Mode 把 預設的 Everything 改成



這樣可以將emgucv  imageBox物件提供的右鍵及滾輪縮放等功能先鎖住!!!!!!



練習畫圖的部分



第一階段程式碼



using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.Util;
using Emgu.CV.ML;

namespace emgucv_note
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            Image<Bgr, byte> imgBg = new Image<Bgr, byte>(512, 512); //畫布  空的  預設黑色           
            //備註:Image<Gray, byte>   預設也是黑色喔!!!

            imageBox1.Image = imgBg;
        }

    }
}




怎麼改變畫布顏色呢??



                                                                            示意圖


第二階段程式碼 _改變背景色 


第一種寫法


imgBg.Data[i, j, 0] = 255;


代碼

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.Util;
using Emgu.CV.ML;

namespace emgucv_note
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            Image<Bgr, byte> imgBg = new Image<Bgr, byte>(512, 512);            
            //Image<Gray, byte> imgGrayBg = new Image<Gray, byte>(512, 512);
            for(int i=0;i<imgBg.Width;i++)
                for(int j=0;j<imgBg.Height;j++)
                {
                    imgBg.Data[i, j, 0] = 255; //B
                    imgBg.Data[i, j, 1] = 0;   //G
                    imgBg.Data[i, j, 2] = 0;   //R
                }
            imageBox1.Image = imgBg;
        }

    }
}



第二種寫法

先取出  畫布資料用  Byte陣列存



代碼

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Emgu.CV;
using Emgu.CV.Structure;
using Emgu.Util;
using Emgu.CV.ML;

namespace emgucv_note
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
            Image<Bgr, byte> imgBg = new Image<Bgr, byte>(512, 512);
            //Image<Gray, byte> imgGrayBg = new Image<Gray, byte>(512, 512);

            byte[] imgTmp = imgBg.Bytes;

            for(int i=0;i<imgBg.Width;i++)
                for(int j=0;j<imgBg.Height;j++)
                {
                    int n = i * imgBg.Width + j; // row-major 的 寫法
                    imgTmp[n * 3] = 0; //B
                    imgTmp[n * 3 + 1] = 255;//G
                    imgTmp[n * 3 + 2] = 0;//R
                }
            imgBg.Bytes = imgTmp;
            imageBox1.Image = imgBg;
        }
    }
}





row-major










A row-major ordered matrix. Elements are stored in memory in the order shown by the arrow.





column-major

















A column-major ordered matrix. Elements are stored in memory in the order shown by the arrow.

留言

這個網誌中的熱門文章

經得起原始碼資安弱點掃描的程式設計習慣培養(五)_Missing HSTS Header

經得起原始碼資安弱點掃描的程式設計習慣培養(三)_7.Cross Site Scripting(XSS)_Stored XSS_Reflected XSS All Clients

(2021年度)駕訓學科筆試準備題庫歸納分析_法規是非題