Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

create a qr code for a programme

+18 votes
asked Sep 5, 2024 by 24CSE037 SASWAT PRIYADARSHI PANDA (220 points)

2 Answers

+1 vote
answered Sep 6, 2024 by Md Shayed Ahmad (160 points)
#include <stdio.h>
#include <qrencode.h>

void generate_qr_code(const char *text) {
    QRcode *qrcode;
    
    qrcode = QRcode_encodeString(text, 0, QR_ECLEVEL_H, QR_MODE_8, 1);

    if(qrcode != NULL) {
        int x, y;
        for(y = 0; y < qrcode->width; y++) {
            for(x = 0; x < qrcode->width; x++) {
                printf("%s", qrcode->data[y * qrcode->width + x] & 1 ? "██" : "  ");
            }
            printf("\n");
        }
        QRcode_free(qrcode);
    } else {
        printf("Failed to generate QR code.\n");
    }
}

int main() {
    char input_text[256];
    
    printf("Enter text to generate QR code: ");
    fgets(input_text, sizeof(input_text), stdin);
    
    generate_qr_code(input_text);
    
    return 0;
}
+1 vote
answered Sep 9, 2024 by Muskan Arjimal (160 points)
#include <opencv2/opencv.hpp>
#include <zbar.h>
#include <stdio.h>

int main() {
    // Initialize OpenCV capture object to capture from default camera (0)
    cv::VideoCapture cap(0);
    
    if (!cap.isOpened()) {
        printf("Error: Could not open the camera.\n");
        return -1;
    }

    // Create an OpenCV Mat object to hold the captured frame
    cv::Mat frame;

    // Initialize ZBar scanner
    zbar::ImageScanner scanner;
    scanner.set_config(zbar::ZBAR_NONE, zbar::ZBAR_CFG_ENABLE, 1);

    while (true) {
        // Capture frame from the camera
        cap >> frame;

        if (frame.empty()) {
            printf("Error: Could not capture frame.\n");
            break;
        }

        // Convert the frame to grayscale
        cv::Mat gray;
        cv::cvtColor(frame, gray, cv::COLOR_BGR2GRAY);

        // Wrap OpenCV image data in a ZBar image
        zbar::Image zbarImage(gray.cols, gray.rows, "Y800", gray.data, gray.cols * gray.rows);

        // Scan the image for QR codes
        int n = scanner.scan(zbarImage);
        if (n > 0) {
            // Extract results
            for (zbar::Image::SymbolIterator symbol = zbarImage.symbol_begin(); symbol != zbarImage.symbol_end(); ++symbol) {
                printf("QR Code detected: %s\n", symbol->get_data().c_str());
            }
        }

        // Display the frame
        cv::imshow("QR Code Scanner", frame);

        // Exit on key press
        if (cv::waitKey(30) >= 0) break;
    }

    // Release the camera
    cap.release();
    return 0;
}
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...