Computer >> कंप्यूटर >  >> प्रोग्रामिंग >> C++

छवि का आकार कैसे बदलें और सी ++ का उपयोग कर ओपनसीवी में सीमा कैसे जोड़ें?

इस विषय में, हम ट्रैकबार का एक और अनुप्रयोग देखेंगे। यहां, हम किसी छवि के आकार को बदलने के लिए ट्रैक-बार का उपयोग करेंगे और छवि में एक बॉर्डर जोड़ेंगे और ट्रैक-बार का उपयोग करके बॉर्डर का आकार बदलेंगे।

निम्नलिखित प्रोग्राम का उपयोग करके, हम एक छवि का आकार बदल सकते हैं, एक सीमा जोड़ सकते हैं, सीमा का आकार बदल सकते हैं और छवि को घुमा सकते हैं। यह पिछले उदाहरण के समान है।

निम्न प्रोग्राम दर्शाता है कि एक ही ट्रैक-बार में एकाधिक स्लाइडर कैसे जोड़ें।

उदाहरण

#include<iostream>
#include<opencv2/highgui/highgui.hpp>
#include<opencv2/imgproc/imgproc.hpp>
using namespace std;
using namespace cv;
   int Rotate = 180;//initializing angle//
   int Scale = 50;//initializing scale//
   int Border = 0;//initial Border//
   Mat before_Rotate;//declaring matrix for before rotation//
   int vertical = 0;//initial vertical value//
   int horizontal = 0;//initial horizontal value//
   void rotator(int, void*){ //function to rotate image//
   Mat Rotation = getRotationMatrix2D(Point(horizontal, vertical),(Rotate - 180), Scale / 50.0);//affine transformation matrix for 2D rotation//
   Mat Rotated;//matrix for rotated image
   warpAffine(before_Rotate, Rotated, Rotation, before_Rotate.size(), INTER_LINEAR, Border, Scalar());//applying affine transformation//
   imshow("RotatedImage", Rotated);//show rotated image//
}
int main(int argc,char**argv) {
   before_Rotate = imread("sky.jpg");//loading image in the matrix//
   vertical = before_Rotate.rows / 2;//getting midpoint of vertical pixels//
   horizontal = before_Rotate.cols / 2;//getting midpoints of horizontal pixels//
   namedWindow("BeforeRotate");//declaring window to show image before rotation//
   imshow("BeforeRotate", before_Rotate);//showing image before rotation//
   namedWindow("AfterRotate");//declaring window to show image after rotation//      
   createTrackbar("Angle", "AfterRotate", &Rotate, 360, rotator);//creating trackbar for rotation//
   createTrackbar("Scale", "AfterRotate", &Scale, 100, rotator);//creating trackbar to change size//
   createTrackbar("Border Mode", "After Rotate", &Border, 5, rotator);//creating trackbar to add border//
   int cbfunction = 0;//initiate value of rotator function's argument//
   rotator(cbfunction, &cbfunction);//call back rotator function//
   waitKey(0);//wait till keystroke//
   return 0;
}

आउटपुट

छवि का आकार कैसे बदलें और सी ++ का उपयोग कर ओपनसीवी में सीमा कैसे जोड़ें?


  1. सी ++ का उपयोग कर ओपनसीवी में बाइनरी छवि कैसे बनाएं?

    एक द्विआधारी छवि सिर्फ एक डिजिटल छवि है जो दो रंगों, काले और सफेद का प्रतिनिधित्व करती है। इमेज प्रोसेसिंग के नजरिए से, बाइनरी इमेज में दो संभावित मानों वाले पिक्सल होते हैं- शून्य और एक। जब पिक्सेल का मान 0 होता है, तो यह एक शुद्ध काले रंग का प्रतिनिधित्व करता है। जब पिक्सेल का मान 1 होता है, तो इस

  1. सी ++ का उपयोग कर ओपनसीवी में किसी छवि के चैनलों की संख्या की गणना कैसे करें?

    इस विषय में, हम समझेंगे कि किसी छवि के चैनलों की संख्या का पता कैसे लगाया जाए। प्रोग्राम चलाने के बाद, कंसोल विंडो में चैनल का नंबर दिखाया जाएगा। चैनल की संख्या प्राप्त करने के लिए, हमने ओपनसीवी के एक वर्ग का उपयोग किया है जिसका नाम चैनल () है। जब हम इमेज मैट्रिक्स को चैनल () वर्ग के ऑब्जेक्ट के रू

  1. सी ++ का उपयोग कर ओपनसीवी में छवि कैसे लोड और दिखाएं?

    इस विषय में, हम यह निर्धारित करेंगे कि C++ में OpenCV का उपयोग करके छवियों को कैसे लोड और दिखाया जाए। OpenCV में एक छवि लोड करने और दिखाने के लिए निम्नलिखित कार्यों की आवश्यकता होती है। चटाई: मैट कोई फंक्शन नहीं है। यह एक डेटा संरचना है, एक प्रकार का चर। सी ++ में इंट, चार, स्ट्रिंग वेरिएबल प्रकार