SlideShare una empresa de Scribd logo
1 de 11
OpenCV Tutorial Part II Loading Images and Using Histograms 29 November 2005 Gavin S Page  [email_address]
Tasks 29 November 2005 Gavin S Page  [email_address] The first step after establishing a working environment is to begin manipulating images. This tutorial will give an introduction to the usage of some basic functions. Steps Performed For explanations on any functions used here see the OpenCV documentat. Load an Image Calculate Histogram Values Calculate Basic Statistics Using Histogram Information
Loading the Image 29 November 2005 Gavin S Page  [email_address] //the name of the image being loaded char* imageName = &quot;Critters_00005.JPG&quot;; //Load the image and make sure that it loads correctly IplImage* im = cvLoadImage(imageName, -1); if( im == 0 ) { //Drop out if the image isn't found std::cerr << &quot;Failed to load: &quot; << imageName << std::endl; return 1; } OpenCV makes it relatively easy to load images. There are several syntax variations that simply take in the path/file name. One is presented here. Use the  cvLoadImage  function to assign the image to an  IplImage  pointer OpenCV uses an  IplImage  to represent image internally. Specify a File to be Loaded Load the File
Specifying a Working Region 29 November 2005 Gavin S Page  [email_address] In order to work with a histogram the image will have to converted to a single plane. //Create a single planed image of the same size as the original IplImage* grayImage = cvCreateImage(cvSize(im->width,im->height),  IPL_DEPTH_8U, 1); //convert the original image to gray cvCvtColor(im, grayImage, CV_BGR2GRAY); //create a rectangular area to evaluate CvRect rect = cvRect(0, 0, 500, 600 ); //apply the rectangle to the image and establish a region of interest cvSetImageROI(grayImage, rect); Convert the Image to Gray Specify a Rectangular Region of Interest (ROI) and apply it to the image The  cvCvtColor  function can be used to convert images to one of several color spaces. To restore the region of interest to the whole image the function  cvResetImageROI  is used Create an Image of  a Single Plane Create the Grayscale Image
Perform Initial Histogram Calculations 29 November 2005 Gavin S Page  [email_address] //create an image to hold the histogram IplImage* histImage = cvCreateImage(cvSize(320,200), 8, 1); //create a histogram to store the information from the image CvHistogram* hist =  cvCreateHist(1, &hist_size, CV_HIST_ARRAY, ranges, 1); //calculate the histogram and apply to hist cvCalcHist( &grayImage, hist, 0, NULL ); //grab the min and max values and their indeces cvGetMinMaxHistValue( hist, &min_value, &max_value, &min_idx, &max_idx); //scale the bin values so that they will fit in the image representation cvScale( hist->bins, hist->bins, ((double)histImage->height)/max_value, 0 ); //set all histogram values to 255 cvSet( histImage, cvScalarAll(255), 0 ); //create a factor for scaling along the width bin_w = cvRound((double)histImage->width/hist_size); OpenCV provides built-in functions to work with histograms. Calculate the Histogram Grab Min/Max Values Set Up Factors For Visualization Create a Histogram Image and a Histogram Create the Histogram Data
Prepare Visualization/Perform Calculations 29 November 2005 Gavin S Page  [email_address] for( i = 0; i < hist_size; i++ ) { //draw the histogram data onto the histogram image cvRectangle( histImage, cvPoint(i*bin_w, histImage->height),   cvPoint((i+1)*bin_w,    histImage->height - cvRound(cvGetReal1D(hist->bins,i))),   cvScalarAll(0), -1, 8, 0 ); //get the value at the current histogram bucket float* bins = cvGetHistValue_1D(hist,i); //increment the mean value mean += bins[0]; } //finish mean calculation mean /= hist_size; //go back through now that mean has been calculated in order to calculate variance for( i = 0; i < hist_size; i++ ) { float* bins = cvGetHistValue_1D(hist,i); variance += pow((bins[0] - mean),2); } //finish variance calculation variance /= hist_size; Here we will iterate across the histogram bins and apply the values to the image while calculating the statistics. Get Values/Perform Calculations Use  cvRectangle  to draw. Draw Values on Image
Display Results 29 November 2005 Gavin S Page  [email_address] std::cout << &quot;Histogram Mean: &quot; << mean << std::endl; std::cout << &quot;Variance: &quot; << variance << std::endl; std::cout << &quot;Standard Deviation: &quot; << sqrt(variance) << std::endl; //display the 3 images cvNamedWindow(&quot;Original&quot;, 0); cvShowImage(&quot;Original&quot;, im ); cvNamedWindow(&quot;Gray&quot;, 0); cvShowImage(&quot;Gray&quot;, grayImage ); cvNamedWindow(&quot;Histogram&quot;, 0); cvShowImage(&quot;Histogram&quot;, histImage ); //hold the images until a key is pressed cvWaitKey(0); This segment displays the visual and textural results. Hold For Input. Passing the parameter “0” waits for a keypress. Output Statistics Display cvNamedWindow  creates a container. The first parameter is the name and the second declares if the container is to expand to fit the contents. Show Images
Cleaning Up 29 November 2005 Gavin S Page  [email_address] //clean up images cvReleaseImage(&histImage); cvReleaseImage(&grayImage); cvReleaseImage(&im); //remove windows cvDestroyWindow(&quot;Original&quot;); cvDestroyWindow(&quot;Gray&quot;); cvDestroyWindow(&quot;Histogram&quot;); Release Images Destroy Containers It is very important to perform clean-up functions. It is easy for memory utilization to go out of control when multiple images are involved.
Results 29 November 2005 Gavin S Page  [email_address] Here are the original image, the grayscale region, and the histogram of that region.
Other Histogram Functions 29 November 2005 Gavin S Page  [email_address] ,[object Object],[object Object],[object Object],[object Object],[object Object]
Revision History 29 November 2005 Gavin S Page  [email_address] Initial Creation: 28 November 2005

Más contenido relacionado

La actualidad más candente

Heap sort &amp; bubble sort
Heap sort &amp; bubble sortHeap sort &amp; bubble sort
Heap sort &amp; bubble sortShanmuga Raju
 
Two-StageCreation
Two-StageCreationTwo-StageCreation
Two-StageCreationgillygize
 
Presentation template - jupyter2slides
Presentation template - jupyter2slidesPresentation template - jupyter2slides
Presentation template - jupyter2slidesDat Tran
 
Stop Programming in JavaScript By Luck
Stop Programming in JavaScript By LuckStop Programming in JavaScript By Luck
Stop Programming in JavaScript By Lucksergioafp
 
Fat Arrow (ES6)
Fat Arrow (ES6)Fat Arrow (ES6)
Fat Arrow (ES6)Ryan Ewing
 
computer notes - Data Structures - 25
computer notes - Data Structures - 25computer notes - Data Structures - 25
computer notes - Data Structures - 25ecomputernotes
 
Mopcon2017 - AppDevKit x CameraKit
Mopcon2017 - AppDevKit x CameraKitMopcon2017 - AppDevKit x CameraKit
Mopcon2017 - AppDevKit x CameraKitanistar sung
 
Yahoo Open Source - The Tour & Mystery of AppDevKit (MOPCON 2016)
Yahoo Open Source - The Tour & Mystery of AppDevKit (MOPCON 2016)Yahoo Open Source - The Tour & Mystery of AppDevKit (MOPCON 2016)
Yahoo Open Source - The Tour & Mystery of AppDevKit (MOPCON 2016)anistar sung
 
Seaborn graphing present
Seaborn graphing presentSeaborn graphing present
Seaborn graphing presentYilin Zeng
 
Data Types and Processing in ES6
Data Types and Processing in ES6Data Types and Processing in ES6
Data Types and Processing in ES6m0bz
 

La actualidad más candente (17)

Heap sort &amp; bubble sort
Heap sort &amp; bubble sortHeap sort &amp; bubble sort
Heap sort &amp; bubble sort
 
Python Programming Essentials - M24 - math module
Python Programming Essentials - M24 - math modulePython Programming Essentials - M24 - math module
Python Programming Essentials - M24 - math module
 
F(2)
F(2)F(2)
F(2)
 
gd
gdgd
gd
 
Two-StageCreation
Two-StageCreationTwo-StageCreation
Two-StageCreation
 
Of class1
Of class1Of class1
Of class1
 
Presentation template - jupyter2slides
Presentation template - jupyter2slidesPresentation template - jupyter2slides
Presentation template - jupyter2slides
 
Grand Central Dispatch
Grand Central DispatchGrand Central Dispatch
Grand Central Dispatch
 
Stop Programming in JavaScript By Luck
Stop Programming in JavaScript By LuckStop Programming in JavaScript By Luck
Stop Programming in JavaScript By Luck
 
Fat Arrow (ES6)
Fat Arrow (ES6)Fat Arrow (ES6)
Fat Arrow (ES6)
 
computer notes - Data Structures - 25
computer notes - Data Structures - 25computer notes - Data Structures - 25
computer notes - Data Structures - 25
 
Mopcon2017 - AppDevKit x CameraKit
Mopcon2017 - AppDevKit x CameraKitMopcon2017 - AppDevKit x CameraKit
Mopcon2017 - AppDevKit x CameraKit
 
Yahoo Open Source - The Tour & Mystery of AppDevKit (MOPCON 2016)
Yahoo Open Source - The Tour & Mystery of AppDevKit (MOPCON 2016)Yahoo Open Source - The Tour & Mystery of AppDevKit (MOPCON 2016)
Yahoo Open Source - The Tour & Mystery of AppDevKit (MOPCON 2016)
 
Seaborn graphing present
Seaborn graphing presentSeaborn graphing present
Seaborn graphing present
 
A tour of Python
A tour of PythonA tour of Python
A tour of Python
 
Number
NumberNumber
Number
 
Data Types and Processing in ES6
Data Types and Processing in ES6Data Types and Processing in ES6
Data Types and Processing in ES6
 

Destacado

Destacado (14)

Filetika 3
Filetika 3Filetika 3
Filetika 3
 
Model / Portret
Model / PortretModel / Portret
Model / Portret
 
A Smiles Driven Invitation
A Smiles Driven InvitationA Smiles Driven Invitation
A Smiles Driven Invitation
 
Open Cv Tutorial Ii
Open Cv Tutorial IiOpen Cv Tutorial Ii
Open Cv Tutorial Ii
 
Presentation Of Items
Presentation Of ItemsPresentation Of Items
Presentation Of Items
 
Cv2009
Cv2009Cv2009
Cv2009
 
Testdellapersonalita3
Testdellapersonalita3Testdellapersonalita3
Testdellapersonalita3
 
Perkembangan Teknologi Komunikasi 2
Perkembangan Teknologi Komunikasi 2Perkembangan Teknologi Komunikasi 2
Perkembangan Teknologi Komunikasi 2
 
Perkembangan Teknologi Komunikasi 1
Perkembangan Teknologi Komunikasi 1Perkembangan Teknologi Komunikasi 1
Perkembangan Teknologi Komunikasi 1
 
consumer newsletter
consumer newsletterconsumer newsletter
consumer newsletter
 
23.oktoobril oli koolis kadrilaat2
23.oktoobril oli koolis kadrilaat223.oktoobril oli koolis kadrilaat2
23.oktoobril oli koolis kadrilaat2
 
Filsafat Etika Komunikasi 2
Filsafat Etika Komunikasi 2Filsafat Etika Komunikasi 2
Filsafat Etika Komunikasi 2
 
Filsafat dan Etika Komunikasi
Filsafat dan Etika KomunikasiFilsafat dan Etika Komunikasi
Filsafat dan Etika Komunikasi
 
Presentasi telekomunikasi
Presentasi telekomunikasiPresentasi telekomunikasi
Presentasi telekomunikasi
 

Similar a Open Cv Tutorial Ii

A basic introduction to open cv for image processing
A basic introduction to open cv for image processingA basic introduction to open cv for image processing
A basic introduction to open cv for image processingChu Lam
 
Histogram dan Segmentasi
Histogram dan SegmentasiHistogram dan Segmentasi
Histogram dan SegmentasiLusiana Diyan
 
Histogram dan Segmentasi 2
Histogram dan Segmentasi 2Histogram dan Segmentasi 2
Histogram dan Segmentasi 2Lusiana Diyan
 
Open Cv 2005 Q4 Tutorial
Open Cv 2005 Q4 TutorialOpen Cv 2005 Q4 Tutorial
Open Cv 2005 Q4 Tutorialantiw
 
I wanted to change the cloudsrectangles into an actuall image it do.pdf
I wanted to change the cloudsrectangles into an actuall image it do.pdfI wanted to change the cloudsrectangles into an actuall image it do.pdf
I wanted to change the cloudsrectangles into an actuall image it do.pdffeelinggifts
 
openFrameworks 007 - graphics
openFrameworks 007 - graphicsopenFrameworks 007 - graphics
openFrameworks 007 - graphicsroxlu
 
CE344L-200365-Lab5.pdf
CE344L-200365-Lab5.pdfCE344L-200365-Lab5.pdf
CE344L-200365-Lab5.pdfUmarMustafa13
 
Palestra - Utilizando tensorflow mobile e seus desafios
Palestra - Utilizando tensorflow mobile e seus desafiosPalestra - Utilizando tensorflow mobile e seus desafios
Palestra - Utilizando tensorflow mobile e seus desafiosGustavo Monteiro
 
Intro to computer vision in .net
Intro to computer vision in .netIntro to computer vision in .net
Intro to computer vision in .netStephen Lorello
 
Webgl para JavaScripters
Webgl para JavaScriptersWebgl para JavaScripters
Webgl para JavaScriptersgerbille
 
Core Image: The Most Fun API You're Not Using, CocoaConf Atlanta, December 2014
Core Image: The Most Fun API You're Not Using, CocoaConf Atlanta, December 2014Core Image: The Most Fun API You're Not Using, CocoaConf Atlanta, December 2014
Core Image: The Most Fun API You're Not Using, CocoaConf Atlanta, December 2014Chris Adamson
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Remy Sharp
 
Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02PL dream
 
Client Side Programming with Applet
Client Side Programming with AppletClient Side Programming with Applet
Client Side Programming with Appletbackdoor
 
Displaying information within a window.68
Displaying information within a window.68Displaying information within a window.68
Displaying information within a window.68myrajendra
 
Getting more out of Matplotlib with GR
Getting more out of Matplotlib with GRGetting more out of Matplotlib with GR
Getting more out of Matplotlib with GRJosef Heinen
 
aip shape detection and tracking using contours
aip shape detection and tracking using contoursaip shape detection and tracking using contours
aip shape detection and tracking using contoursSaeed Ullah
 
Creating an Uber Clone - Part IV - Transcript.pdf
Creating an Uber Clone - Part IV - Transcript.pdfCreating an Uber Clone - Part IV - Transcript.pdf
Creating an Uber Clone - Part IV - Transcript.pdfShaiAlmog1
 

Similar a Open Cv Tutorial Ii (20)

A basic introduction to open cv for image processing
A basic introduction to open cv for image processingA basic introduction to open cv for image processing
A basic introduction to open cv for image processing
 
Histogram dan Segmentasi
Histogram dan SegmentasiHistogram dan Segmentasi
Histogram dan Segmentasi
 
Histogram dan Segmentasi 2
Histogram dan Segmentasi 2Histogram dan Segmentasi 2
Histogram dan Segmentasi 2
 
Open Cv 2005 Q4 Tutorial
Open Cv 2005 Q4 TutorialOpen Cv 2005 Q4 Tutorial
Open Cv 2005 Q4 Tutorial
 
I wanted to change the cloudsrectangles into an actuall image it do.pdf
I wanted to change the cloudsrectangles into an actuall image it do.pdfI wanted to change the cloudsrectangles into an actuall image it do.pdf
I wanted to change the cloudsrectangles into an actuall image it do.pdf
 
Cpp tutorial
Cpp tutorialCpp tutorial
Cpp tutorial
 
openFrameworks 007 - graphics
openFrameworks 007 - graphicsopenFrameworks 007 - graphics
openFrameworks 007 - graphics
 
CE344L-200365-Lab5.pdf
CE344L-200365-Lab5.pdfCE344L-200365-Lab5.pdf
CE344L-200365-Lab5.pdf
 
Palestra - Utilizando tensorflow mobile e seus desafios
Palestra - Utilizando tensorflow mobile e seus desafiosPalestra - Utilizando tensorflow mobile e seus desafios
Palestra - Utilizando tensorflow mobile e seus desafios
 
Intro to computer vision in .net
Intro to computer vision in .netIntro to computer vision in .net
Intro to computer vision in .net
 
Webgl para JavaScripters
Webgl para JavaScriptersWebgl para JavaScripters
Webgl para JavaScripters
 
Core Image: The Most Fun API You're Not Using, CocoaConf Atlanta, December 2014
Core Image: The Most Fun API You're Not Using, CocoaConf Atlanta, December 2014Core Image: The Most Fun API You're Not Using, CocoaConf Atlanta, December 2014
Core Image: The Most Fun API You're Not Using, CocoaConf Atlanta, December 2014
 
Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)Is HTML5 Ready? (workshop)
Is HTML5 Ready? (workshop)
 
Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02Is html5-ready-workshop-110727181512-phpapp02
Is html5-ready-workshop-110727181512-phpapp02
 
Client Side Programming with Applet
Client Side Programming with AppletClient Side Programming with Applet
Client Side Programming with Applet
 
Displaying information within a window.68
Displaying information within a window.68Displaying information within a window.68
Displaying information within a window.68
 
Getting more out of Matplotlib with GR
Getting more out of Matplotlib with GRGetting more out of Matplotlib with GR
Getting more out of Matplotlib with GR
 
Dip iit workshop
Dip iit workshopDip iit workshop
Dip iit workshop
 
aip shape detection and tracking using contours
aip shape detection and tracking using contoursaip shape detection and tracking using contours
aip shape detection and tracking using contours
 
Creating an Uber Clone - Part IV - Transcript.pdf
Creating an Uber Clone - Part IV - Transcript.pdfCreating an Uber Clone - Part IV - Transcript.pdf
Creating an Uber Clone - Part IV - Transcript.pdf
 

Último

New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 

Último (20)

New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 

Open Cv Tutorial Ii

  • 1. OpenCV Tutorial Part II Loading Images and Using Histograms 29 November 2005 Gavin S Page [email_address]
  • 2. Tasks 29 November 2005 Gavin S Page [email_address] The first step after establishing a working environment is to begin manipulating images. This tutorial will give an introduction to the usage of some basic functions. Steps Performed For explanations on any functions used here see the OpenCV documentat. Load an Image Calculate Histogram Values Calculate Basic Statistics Using Histogram Information
  • 3. Loading the Image 29 November 2005 Gavin S Page [email_address] //the name of the image being loaded char* imageName = &quot;Critters_00005.JPG&quot;; //Load the image and make sure that it loads correctly IplImage* im = cvLoadImage(imageName, -1); if( im == 0 ) { //Drop out if the image isn't found std::cerr << &quot;Failed to load: &quot; << imageName << std::endl; return 1; } OpenCV makes it relatively easy to load images. There are several syntax variations that simply take in the path/file name. One is presented here. Use the cvLoadImage function to assign the image to an IplImage pointer OpenCV uses an IplImage to represent image internally. Specify a File to be Loaded Load the File
  • 4. Specifying a Working Region 29 November 2005 Gavin S Page [email_address] In order to work with a histogram the image will have to converted to a single plane. //Create a single planed image of the same size as the original IplImage* grayImage = cvCreateImage(cvSize(im->width,im->height), IPL_DEPTH_8U, 1); //convert the original image to gray cvCvtColor(im, grayImage, CV_BGR2GRAY); //create a rectangular area to evaluate CvRect rect = cvRect(0, 0, 500, 600 ); //apply the rectangle to the image and establish a region of interest cvSetImageROI(grayImage, rect); Convert the Image to Gray Specify a Rectangular Region of Interest (ROI) and apply it to the image The cvCvtColor function can be used to convert images to one of several color spaces. To restore the region of interest to the whole image the function cvResetImageROI is used Create an Image of a Single Plane Create the Grayscale Image
  • 5. Perform Initial Histogram Calculations 29 November 2005 Gavin S Page [email_address] //create an image to hold the histogram IplImage* histImage = cvCreateImage(cvSize(320,200), 8, 1); //create a histogram to store the information from the image CvHistogram* hist = cvCreateHist(1, &hist_size, CV_HIST_ARRAY, ranges, 1); //calculate the histogram and apply to hist cvCalcHist( &grayImage, hist, 0, NULL ); //grab the min and max values and their indeces cvGetMinMaxHistValue( hist, &min_value, &max_value, &min_idx, &max_idx); //scale the bin values so that they will fit in the image representation cvScale( hist->bins, hist->bins, ((double)histImage->height)/max_value, 0 ); //set all histogram values to 255 cvSet( histImage, cvScalarAll(255), 0 ); //create a factor for scaling along the width bin_w = cvRound((double)histImage->width/hist_size); OpenCV provides built-in functions to work with histograms. Calculate the Histogram Grab Min/Max Values Set Up Factors For Visualization Create a Histogram Image and a Histogram Create the Histogram Data
  • 6. Prepare Visualization/Perform Calculations 29 November 2005 Gavin S Page [email_address] for( i = 0; i < hist_size; i++ ) { //draw the histogram data onto the histogram image cvRectangle( histImage, cvPoint(i*bin_w, histImage->height), cvPoint((i+1)*bin_w, histImage->height - cvRound(cvGetReal1D(hist->bins,i))), cvScalarAll(0), -1, 8, 0 ); //get the value at the current histogram bucket float* bins = cvGetHistValue_1D(hist,i); //increment the mean value mean += bins[0]; } //finish mean calculation mean /= hist_size; //go back through now that mean has been calculated in order to calculate variance for( i = 0; i < hist_size; i++ ) { float* bins = cvGetHistValue_1D(hist,i); variance += pow((bins[0] - mean),2); } //finish variance calculation variance /= hist_size; Here we will iterate across the histogram bins and apply the values to the image while calculating the statistics. Get Values/Perform Calculations Use cvRectangle to draw. Draw Values on Image
  • 7. Display Results 29 November 2005 Gavin S Page [email_address] std::cout << &quot;Histogram Mean: &quot; << mean << std::endl; std::cout << &quot;Variance: &quot; << variance << std::endl; std::cout << &quot;Standard Deviation: &quot; << sqrt(variance) << std::endl; //display the 3 images cvNamedWindow(&quot;Original&quot;, 0); cvShowImage(&quot;Original&quot;, im ); cvNamedWindow(&quot;Gray&quot;, 0); cvShowImage(&quot;Gray&quot;, grayImage ); cvNamedWindow(&quot;Histogram&quot;, 0); cvShowImage(&quot;Histogram&quot;, histImage ); //hold the images until a key is pressed cvWaitKey(0); This segment displays the visual and textural results. Hold For Input. Passing the parameter “0” waits for a keypress. Output Statistics Display cvNamedWindow creates a container. The first parameter is the name and the second declares if the container is to expand to fit the contents. Show Images
  • 8. Cleaning Up 29 November 2005 Gavin S Page [email_address] //clean up images cvReleaseImage(&histImage); cvReleaseImage(&grayImage); cvReleaseImage(&im); //remove windows cvDestroyWindow(&quot;Original&quot;); cvDestroyWindow(&quot;Gray&quot;); cvDestroyWindow(&quot;Histogram&quot;); Release Images Destroy Containers It is very important to perform clean-up functions. It is easy for memory utilization to go out of control when multiple images are involved.
  • 9. Results 29 November 2005 Gavin S Page [email_address] Here are the original image, the grayscale region, and the histogram of that region.
  • 10.
  • 11. Revision History 29 November 2005 Gavin S Page [email_address] Initial Creation: 28 November 2005