Skip to main content

how to convert an image to Grey scale using the opencv4nodejs package in Hindi | opencv rgb to grey | bgr to grey opencv |  opencv node imread

इस tutorial में हम सीखेंगे कि opencv4nodejs पैकेज का उपयोग करके किसी image को grey scale में कैसे convert किया जाए।


Image को grey scale में कैसे convert करें

OpenCV के किसी भी function का उपयोग करने के लिए सबसे पहले हमें  opencv4nodejs module को load करना पड़ेगा। निचे दी हुई लाइन OpenCV को load करेगी।

 
const cv = require('opencv4nodejs');


एक बार OpenCV लोड करने के बाद हम उस इमेज को read करेंगे जिसे हम grey scale में convert करना चाहते है। OpenCV इस्तेमाल करने के लिए आपको cv इस keyword को इस्तेमाल करना पड़ेगा, जो original photo को read करने के लिए और इसे greyscale में परिवर्तित करने के लिए आवश्यक चीजे उपलब्ध कराएगा।


original photo को read करने के लिए, बस cv मॉड्यूल के imread() function को कॉल करें, image path को string के रूप में इस्तेमाल करें।

var image = cv.imread('C:/Users/Admin/Desktop/photo.jpg')

अब अगला स्टेप है, इस image को greyscale mode में convert करना। इसके लिए हमें OpenCv का bgrToGray function इस्तेमाल करना पड़ेगा, जो हमें साधारण रंगीन image से greyscale इमेज में convert करने में मदद करेगा।

यह function कोई argument नहीं लेती है और यह grey scale image  के साथ Mat Class के किसी अन्य object के output के रूप में वापस आती है।

const greyImg  = originalImage.bgrToGray();

अब हम इस grey scale image को अपने window में दिखाएंगे। इसके लिए हम OpenCV के imshow() function का इस्तेमाल करेंगे।

cv.imshow('Grey Image', greyImg);  
  

साथ में हम original image भी दिखाएंगे जिससे हमें comparison करने में आसानी हो। 

cv.imshow('Original Image', image);
    

आखिर में हम waitKey function  इस्तेमाल करेंगे, जो execution को तब तक रोकेगा जब तक हम किसी key पर क्लिक नहीं करते।

cv.waitKey();
    

Final Code

अंत में code कुछ ऐसा होगा। 

/* step I - loading OpenCV module */
const cv = require('opencv4nodejs');
 
/* Step II - Loading of Image */
const image = cv.imread('C:/Users/Admin/Desktop/photo.jpg');
 
/* Conversion - RGB to Grey */
const greyImg = image.bgrToGray();
 
/* showing of images RGB and GREY*/
cv.imshow('Original Image', image);
cv.imshow('Grey Image', greyImg);
 
/* calling of waitKey function */
cv.waitKey();
   

Output

Original Image

OpenCV RGB to GreyScale - Original Image

Grey Image

OpenCV RGB to GreyScale - Grey Image

Popular posts from this blog

CCAvenue avoid Error Code 21002 currency required parameter missing

In this tutorial, we will see how to avoid Error Code 21002 currency required parameter missing. This is a usual problem that occurs after connecting our application to the CCAvenue payment gateway. Due to some input values that are missing by developers while coding, such error occurs. CCAvenue is one of the leading online payment gateway service provider similar to other popular providers PayPal, Citrus, PayUMoney etc. Easy integration is an advantage of CCAvenue payment gateway. But, due to very minor mistakes in coding, developers get few errors while integrating CCAvenue with their application. CCAvenue have provided some guidelines of integration that are necessarily needed to be followed while integrating it into the application. Inputs values like amount, currency, merchant_id, redirect_url, cancel_url etc are minimum required and should be included in the form before sending the data to CCAvenue page. If we avoid them or forgot to use them into the code, CCAvenue th

CCAvenue avoid Error Code 21003 amount required parameter missing

In this tutorial, we will see how to avoid Error Code 21003 amount required parameter missing. This is another problem that occurs due to very minor mistake made by developer after connecting an application to the CCAvenue payment gateway. Due to some input values that are missing by developers while coding, such error occurs. CCAvenue is one of the leading online payment gateway service provider similar to other popular providers PayPal, Citrus, PayUMoney etc. Easy integration is an advantage of CCAvenue payment gateway. As per the guidelines of integration provided by CCAvenue that are necessarily needed to be followed while integrating it into the application. Input values like amount, currency, merchant_id, redirect_url, cancel_url etc are minimum required and should be included in the form before sending the data to CCAvenue page. If we avoid them or forgot to use them into the code, CCAvenue throws an error. As mentioned above, Amount is one of the required values that

CCAvenue avoid Error Code 21001 order id required parameter missing

In this tutorial, we will see how to avoid Error Code 21001 order_id required parameter missing. This is a usual problem that occurs after connecting our application to the CCAvenue payment gateway. But, it is not a big issue to solve. CCAvenue is one of the leading online payment gateway service provider similar to other popular providers PayPal, Citrus, PayUMoney etc. Easy integration is an advantage of CCAvenue payment gateway. But, due to very minor mistakes in coding, developers get few errors while integrating CCAvenue with their application. CCAvenue have provided some guidelines of integration that are necessarily needed to follow while integrating it into the application. It includes some parameters or inputs that are minimum required like amount, currency, merchant_id, redirect_url, cancel_url etc. If we avoid them or forgot to use them into the code, CCAvenue throws the error. As mentioned above Order Id is one of the required values that should be mentioned in co