public ROOTNET.NTH1I[] GetHistogram(uint channel, byte binning)
        {
            //Get the registers for the requested channel
            GetRegisters(channel);

            //Get the read/write addresses which are important for starting and reading the histograms
            uint[,] channels = AFE_ChannelAddresses(channel);
            //0x60
            uint histCntrl_Dark_Base = 0x60 + (uint)Ext_mode + channels[0, 4]; // This turns on the histogramming with the defined mode

            //binning should only be 1, 2, 4, or 8, since those are the only supported histogram bin widths
            switch (binning)
            {
            case 1:
                histCntrl_Dark_Base += 0x0;
                break;

            case 2:
                histCntrl_Dark_Base += 0x500;
                break;

            case 4:
                histCntrl_Dark_Base += 0xA00;
                break;

            case 8:
                histCntrl_Dark_Base += 0xF00;
                break;

            default:
                histCntrl_Dark_Base += 0x0;
                break;
            }

            //Get the registers specific to the requested channel
            SetRegisters();

            //Start the histogramming and wait for it to finish (very quick)
            Mu2e_Register.WriteReg(histCntrl_Dark_Base, ref histo_controls[0], ref febClient.client);
            System.Threading.Thread.Sleep(accumulation_interval + 50); //small bit of time buffer added to the interval

            //Get and unpack the data
            UInt32[][] histogramBinContents = ParseData(ReceiveData(channel));

            //Fill the histograms
            ROOTNET.NTH1I[] histo = new ROOTNET.NTH1I[2];
            for (uint i = 0; i < 2; i++)
            {
                histo[i] = new ROOTNET.NTH1I("Ch" + channels[i, 3].ToString(), channels[i, 3].ToString(), 512, 0, binning * 512);
                for (uint binIndex = 0; binIndex < histogramBinContents[i].Length; binIndex++)
                {
                    histo[i].SetBinContent((int)binIndex, histogramBinContents[i][binIndex]);
                }
                histo[i].GetXaxis().SetTitle("ADC");
                histo[i].GetYaxis().SetTitle("N");
            }

            //Return the histograms
            return(histo);
        }
Пример #2
0
        public ROOTNET.NTH1I[] GetHistogram(uint channel, string suffix = "")
        {
            channel %= 8;                                               //requested channel mod 8 (since each AFE only cares about the 8 channels connected to it)

            SetRegisters();                                             //Preps the FEB (re-sets accumulation interval and resets the read pointers)
            uint histCntrl_Dark_Base = 0x60 + (uint)Ext_mode + channel; // This is the "on" command for the histogramming and setting for gated histograms and the channel requested

            //Start the histogramming and wait for it to finish (very quick)
            Mu2e_Register.WriteReg(histCntrl_Dark_Base, ref histo_controls[0], ref febClient.client);
            System.Threading.Thread.Sleep(accumulation_interval + 250); //small bit of time buffer added to the interval

            //Get and unpack the data
            UInt32[][] histogramBinContents = ParseData(ReceiveData(channel));

            //Fill the histograms
            ROOTNET.NTH1I[] histo = new ROOTNET.NTH1I[read_addrs.Length];
            for (uint i = 0; i < read_addrs.Length; i++)
            {
                try
                {
                    histo[i] = new ROOTNET.NTH1I("Ch" + ((8 * i) + channel).ToString() + suffix, ((8 * i) + channel).ToString(), num_bins, 0, num_bins); //First bin is underflow, last bin is overflow
                    for (uint binIndex = 0; binIndex < histogramBinContents[i].Length; binIndex++)
                    {
                        histo[i].SetBinContent((int)binIndex + 1, histogramBinContents[i][binIndex]);
                    }
                    histo[i].GetXaxis().SetTitle("ADC");
                    histo[i].GetYaxis().SetTitle("N");
                }
                catch (NullReferenceException)
                {
                    //leave it as an empty histogram
                    histo[i].GetXaxis().SetTitle("ADC");
                    histo[i].GetYaxis().SetTitle("N");
                }
            }

            //Return the histograms
            return(histo);
        }
Пример #3
0
        static void Main(string[] args)
        {
            List <string> tempFileList = new List <string>();

            //var h = new ROOTNET.NTH1F();


            //File list from Blizz Americas Championship
            //tempFileList.Add("test.png");
            //tempFileList.Add("test480.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h19m07s974.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h19m25s545.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h19m35s253.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h19m55s213.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h19m59s995.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h20m11s857.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h20m19s473.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h20m35s166.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h20m38s961.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h20m56s916.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h21m03s792.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h21m30s637.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h21m36s183.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h22m00s213.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h22m09s622.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h22m22s416.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h22m33s378.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h22m45s875.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h22m50s183.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h23m06s850.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h23m11s075.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h23m20s624.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h23m25s391.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h23m35s019.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h23m39s636.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h23m49s060.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h24m34s479.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h24m44s448.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h24m56s372.png");
            tempFileList.Add("testImages/vlcsnap-2015-09-24-01h25m05s414.png");

            fileImageProducer blizzAmericas = new fileImageProducer(tempFileList);

            var newFile = new ROOTNET.NTFile("output.root", "RECREATE");
            //String win1 = "Edge output test"; //Window name
            //CvInvoke.NamedWindow(win1); //Create the window with the name persona 3 style
            Mat outImage = new Mat();

            RegionOfInterest leftBlizz  = new RegionOfInterest(510f / 1280f, 0f / 720f, 100f / 1280f, 20f / 700f);
            RegionOfInterest rightBlizz = new RegionOfInterest(665f / 1280f, 0f / 720f, 100f / 1280f, 20f / 700f);

            var bestRowHisto = new ROOTNET.NTH1I("bestRows", "Top rows by discrimination", 20, 0, 20);
            //newFile.Add(bestRowHisto);

            //Text for comparison. "TEMPO STORM"
            TextSize    textSizeTest    = new TextSize(leftBlizz.getROIImage(blizzAmericas.ElementAt(0).loadedImage));
            PeakPattern peakPatternTest = new PeakPattern(leftBlizz.getROIImage(blizzAmericas.ElementAt(0).loadedImage), 200.0);

            //PeakPattern peakPatternTest2 = new PeakPattern(rightBlizz.getROIImage(blizzAmericas.Last().loadedImage));

            for (int iImage = 0; iImage < blizzAmericas.Count(); iImage++)
            {
                Image testc       = blizzAmericas.ElementAt(iImage);
                Mat   leftRegion  = leftBlizz.getROIImage(testc.loadedImage);
                Mat   rightRegion = rightBlizz.getROIImage(testc.loadedImage);

                List <Tuple <int, int> > rowResult = topThree(entropyList <Bgr, byte>(leftRegion, rightRegion, new byte[] { 180, 180, 180 }));

                ROOTNET.NTH1F tempLeft  = drawHisto <Bgr, double>(leftRegion, rowResult[0].Item1, 0, "left " + iImage);
                ROOTNET.NTH1F tempRight = drawHisto <Bgr, double>(rightRegion, rowResult[0].Item1, 0, "right " + iImage);

                //newFile.Add(tempLeft);
                //newFile.Add(tempRight);

                bestRowHisto.Fill(rowResult[0].Item1);
                bestRowHisto.Fill(rowResult[1].Item1);
                bestRowHisto.Fill(rowResult[3].Item1);

                //Console.WriteLine("Row {0} with {1}, row {2} with {3}, row {4} with {5}.",
                //    rowResult[0].Item1, rowResult[0].Item2,
                //    rowResult[1].Item1, rowResult[1].Item2,
                //    rowResult[2].Item1, rowResult[2].Item2);
                Console.WriteLine("File {0}", tempFileList[iImage]);
                //Console.WriteLine("TextSize Probability left {0}, TextSize probability right {1}.",
                //    textSizeTest.ProbabilityMatch(leftRegion),
                //    textSizeTest.ProbabilityMatch(rightRegion));
                Console.WriteLine("PeakPattern cosine left {0}, PeakPattern cosine right {1}.",
                                  peakPatternTest.ProbabilityMatch(leftRegion),
                                  peakPatternTest.ProbabilityMatch(rightRegion));
            }


            //CvInvoke.Imshow(win1, testMat);
            //TesseractEngine testOCR = new TesseractEngine("langDat", "eng", Tesseract.EngineMode.Default);
            //testOCR.DefaultPageSegMode(Tesseract.PageSegMode.SingleChar);
            //testOCR.

            //ImageViewer.Show(outImage, "test");

            //Some numbers from a 720p image in paint for ROI testing.

            //ImageViewer.Show(leftBlizz.getROIImage(blizzAmericas.ElementAt(0).loadedImage), "leftName");
            //ImageViewer.Show(rightBlizz.getROIImage(blizzAmericas.ElementAt(0).loadedImage), "rightName");

            Mat testProcessing      = leftBlizz.getROIImage(blizzAmericas.ElementAt(0).loadedImage);
            Mat testProcessingRight = rightBlizz.getROIImage(blizzAmericas.ElementAt(1).loadedImage);

            System.Drawing.Rectangle textRegion  = ProcessingTools.findTextEdge <Bgr, double>(testProcessing, new double[] { 180.0, 180.0, 180.0 });
            System.Drawing.Rectangle textRegion2 = ProcessingTools.findTextEdge <Bgr, double>(testProcessingRight, new double[] { 180.0, 180.0, 180.0 });

            //CvInvoke.Rectangle(testProcessing, textRegion, new Bgr(0, 0, 255).MCvScalar);
            //ImageViewer.Show(leftBlizz.getROIImage(blizzAmericas.ElementAt(0).loadedImage), "leftName");

            //CvInvoke.Rectangle(testProcessingRight, textRegion2, new Bgr(0, 0, 255).MCvScalar);
            //ImageViewer.Show(testProcessingRight, "rightName");



            //ImageViewer.Show(testProcessing);
            //Mat[] leftBlizzChannels = leftBlizz.getROIImage(outImage).Split();
            //Mat[] rightBlizzChannels = rightBlizz.getROIImage(outImage).Split();

            //foreach( Mat iMat in leftBlizzChannels)
            //{
            //    ImageViewer.Show(iMat);
            //}

            Console.ReadKey(); //Wait for return to finish!
            newFile.Write();
            //newFile.Close();
        }